我对 RSpec 测试有疑问。我正在使用 FactoryGirl、Capybara 2.* 并尝试测试我的网站行为。
测试场景:用户点击登录按钮(设计控制器),他被重定向到root_path(由MyController管理)。在他的重定向之后 before_filter :setup_params 应该分配给@app 变量(在 MyController 中的操作 :find_apps)一些值。我想确保 @app 不是 nil 并且分配了值。
这是我的 sign_in_spec.rb
require "spec_helper.rb"
require "mymodel.rb"
describe MyContoller, :type => :feature do
before do
visit '/users/sign_in'
end
it "Shall redirect to user and ensure that @app is not nil" do
user = FactoryGirl.build(:user_monit)
fill_in "user[email]", with: user.email
fill_in "user[password]", with: user.password
#expect {click_button "Sign in"}.to change {@myapp}.from(nil)
click_button "Sign in"
get :find_apps
assigns(:myapp).should_not be_nil
end
end
我的 spec_helper.rb 中的 require 部分
require 'rspec/rails'
require 'rspec/autorun'
require 'capybara/rails'
require 'capybara/rspec'
require 'mocha/setup'
require 'factory_girl'
....
config.include RSpec::Rails::RequestExampleGroup, type: :feature
我有几个错误:
1) result should have changed, but is still nil
2) bad argument error for get :find_apps (ArgumentError: bad argument (expected URI object or URI string))
我究竟做错了什么?
提前致谢!