我想测试使用MINITEST和webrat红宝石认证应用程序,但出现错误。
像测试visit '/'
失败,错误Status 200 expected but was 404.
含像代码测试fill_in :email, :with => "first@company.com"
失败,错误Could not find field: :email
。
我看了几西纳特拉,测试和webrat文件和论坛。 他们中的一些老建议的东西一样西纳特拉::默认设置,但github.com/brynary/webrat/wiki/sinatra , 构建西纳特拉应用驱动下Webrat测试和学习从大师:西纳特拉内幕是新的,但他们仍然会失败。
基本上,我不喜欢RSpec的,黄瓜等句子的语法,但做想做的事的行为驱动开发。 我真的很喜欢MINITEST语法,这两个测试和输出,这就是为什么我选择BDD webrat。 如果我错了期待webrat履行验收测试的需求,请直接告诉我,我应该用这个框架或那一个。
除此之外,主文件和测试文件的第一部分如下。 我希望有人能解释我,我很想念?
test_file里面
require "test/unit"
require "minitest/autorun"
require "rack/test"
require 'webrat'
require_relative "../lib/kimsin.rb"
Webrat.configure do |config|
config.mode = :rack
end
ENV["RACK_ENV"] = "test"
class KimsinTests < Test::Unit::TestCase
include Rack::Test::Methods
include Webrat::Methods
include Webrat::Matchers
def app
Sinatra::Application.new
end
def test_create_user
visit "/user/new"
fill_in :username, :with => "first@company.com"
fill_in :password, :with => "abC123?*"
fill_in :confirm_password, :with => "abC123?*"
click_link "Register"
assert 201, last_response.status, "Status 201 expected but was #{last_response.status}.\n#{error}"
assert_contain /Logged in as first@company.com./, "No user created"
assert_contain /Logout/, "Logout link not present"
end
main_file
require "sinatra"
require "erb"
require_relative "../lib/kimsin/version"
require_relative "../lib/kimsin/user"
class Kimsin < Sinatra::Application
use Rack::Session::Pool, :expire_after => 2592000
set :session_secret, BCrypt::Engine.generate_salt
configure :development do
DataMapper.auto_migrate!
end
get "/" do
if session[:user_id]
user = User.get session[:user_id]
email = user.email
erb :index, :locals => { :email => email }
else
email = nil
erb :index, :locals => { :email => email }
end
end