0
我有RSpec测试的问题。我正在使用FactoryGirl,Capybara 2. *并尝试测试我的网站行为。RSpec。 Rails 3.2。实例变量检查。行为测试
测试场景: 用户点击sign_in按钮(设计控制器),他被重定向到root_path(由MyController管理)。在重定向before_filter之后:setup_params应该分配给@app变量(在action中:MyController中的find_apps)一些值。我想确保@app不是零,而是赋值。
这里是我的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 '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))
我在做什么错?
在此先感谢!
谢谢,但我有得到ActiveRecord :: RecordInvalid:错误记录无效。当我使用FactoryGirl.build时,我可以通过任何测试重定向 - “断言has_selector?”表#admin-credit-application'“在click_button”登录“后返回true –
如果你不能创建:user_monit也许与你工厂不好。 – Adeptus
它的控制器测试不被接受,所以你可以像租用测试: [link](https://github.com/plataformatec/devise/wiki/How-To:-Controllers-tests-with-Rails-3-(and- rspec)) 如果你想与Capybara接受测试,你可以找到帮助雇用: [链接](https://github.com/plataformatec/devise/wiki/How-To:-Test-with-Capybara) – Adeptus