使用Rails 3.2和最新的Rspec和Capybara,這意味着我的水豚規格生活在spec/features
。試圖用rspec&水豚測試omniauth,失敗
我對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
包括config.include IntegrationSpecHelper, :type => :request
的Rspec.configure
內做塊。
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(試圖保持簡單)。
任何想法可能是什麼問題?提前致謝!