【发布时间】:2013-04-18 02:57:52
【问题描述】:
使用 Rails 3.2 和最新的 Rspec 和 Capybara,这意味着我的 Capybara 规范位于 spec/features。
我对 Rails 和测试非常陌生,但我想习惯测试。我最终在测试之前实现了 OAuth。我终于让它工作了,现在我正在尝试追溯测试它(所以我至少知道它是否会在未来发生故障)。我正在尝试关注this tutorial,但没有成功。这是我所做的:
1) 创建spec/support/integration_spec_helper.rb 使用:
module IntegrationSpecHelper
def login_with_oauth(service = :google)
visit "/auth/#{service}"
end
end
2) 修改 spec/spec_helper 以在 Rspec.configure do 块中包含 config.include IntegrationSpecHelper, :type => :request。
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(试图让事情变得简单)。
知道问题可能是什么吗?提前致谢!
【问题讨论】:
标签: ruby-on-rails rspec capybara