使用 Rails 3.2 和最新的 Rspec 和 Capybara,这意味着我的 Capybara 规范存在于spec/features
.
我对 Rails 和测试真的很陌生,但我想习惯测试。我最终在测试之前实现了 OAuth。我终于让它工作了,现在我正在尝试追溯测试它(所以我至少知道它是否会在未来发生故障)。我正在尝试按照本教程进行操作,但是没有用。这是我所做的:
1) 创建spec/support/integration_spec_helper.rb
于:
module IntegrationSpecHelper
def login_with_oauth(service = :google)
visit "/auth/#{service}"
end
end
2) 修改spec/spec_helper
为包含config.include IntegrationSpecHelper, :type => :request
在Rspec.configure
do 块内。
3) 创建spec/features/omniauth_spec.rb
于:
require 'spec_helper'
feature 'testing oauth' do
scenario 'should create a new tiger' do
login_with_oauth
visit new_tiger_path
fill_in 'tiger_name', :with => 'Charlie'
fill_in 'tiger_blood', :with => 'yes'
click_on 'Create Tiger'
page.should have_content("Thanks! You are a winner!")
end
end
当然它会失败(我的应用程序中没有老虎),但我希望它在visit new_tiger_path
. 相反,运行规范,我得到:
1) testing oauth should create a new tiger
Failure/Error: login_with_oauth
NameError:
undefined local variable or method `login_with_oauth' for #<RSpec::Core::ExampleGroup::Nested_3:0x83355d8>
# ./spec/features/omniauth_spec.rb:4:in `block (2 levels) in <top (required)>'
所以基本上,它说没有这样的事情login_with_oauth
。这一定是一个非常基本的错误,因为由于某种原因我的代码没有包含在内。
我没有使用 spork (试图让事情变得简单)。
知道问题可能是什么吗?提前致谢!