我目前使用 devise 作为身份验证,使用 capybara + rspec 作为我的测试环境。
并且有一个奇怪的行为,管理员似乎被意外注销。
这是我的测试代码
require 'spec_helper'
require 'helpers/myapp/login_helper'
describe "Crawler" do
describe "UpdateMainMenus" do
it "should work" do
@admin = FactoryGirl.create(:myapp_admin)
login_as @admin, :scope => :admin
visit admin_cron_jobs_url(subdomain: "myapp")
current_url.should == admin_cron_jobs_url(subdomain: "myapp")
puts ""
puts current_url
visit admin_cron_jobs_url(subdomain: "myapp")
current_url.should == admin_cron_jobs_url(subdomain: "myapp")
puts ""
puts current_url
end
end
end
还有 helpers/myapp/login_helper.rb
include Warden::Test::Helpers
Warden.test_mode!
我已经在 rspec_helper.rb 中设置了 Warden
config.after(:each) { Warden.test_reset! }
输出是:
http://myapp.example.com/admin/cron_jobs
F
Failures:
1) Crawler UpdateMainMenus should work
Failure/Error: current_url.should == admin_cron_jobs_url(subdomain: "myapp")
expected: "http://myapp.example.com/admin/cron_jobs"
got: "http://myapp.example.com/admins/sign_in" (using ==)
# ./spec/requests/myapp/crawler_spec.rb:30:in `block (3 levels) in <top (required)>'
Finished in 5.44 seconds
1 example, 1 failure
任何帮助表示赞赏..真的谢谢