spec_helper.rb 源码
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'capybara/rspec'
require 'authlogic/test_case' # include at the top of test_helper.rb
include Authlogic::TestCase
test_spec.rb 源
require 'spec_helper'
describe "Stackoverflow" do
describe "GET /test" do
it "is logged in #1" do
activate_authlogic
user = FactoryGirl.create(:user)
UserSession.create(user)
get page_path('test')
response.body.should include('YES')
end
it "is logged in #2" do
activate_authlogic
user = FactoryGirl.create(:user)
UserSession.find
get page_path('test')
response.body.should include('YES')
end
end
end
test.html.erb 源码
<% if current_user %>
YES LOGGED IN
<% else %>
NOT LOGGED IN
<% end %>
截图它在我的浏览器中运行
- Chrome 已登录
- Opera 已注销
问题
我的两个测试都失败了。Authlogic 似乎没有创建/查找会话。我的观点应该是“YES LOGGED IN”。如果我没有展示相关内容,您可以查看我的完整源代码