我用Rspec + Capybara設置我的測試環境,但是我得到了這個未定義的last_response。我正在通過網絡搜索,所以。我發現了幾個關於版本的東西,使用git repo而不是rubygem源碼等等......但它並沒有改變我的線索。Rspec +水豚:undefined last_response
這裏回溯: rspec的--backtrace規格/控制器/ API/plist中/ providers_listing_spec.rb 失敗:
1) Api::Plist::ProvidersController should return a successfull plist containing a list of providers
Failure/Error: last_response.status.shoud be_success
NameError:
undefined local variable or method `last_response' for #<RSpec::Core::ExampleGroup::Nested_1:0x105658e10>
# ./.gems/ruby/1.8/gems/rspec-expectations-2.6.0/lib/rspec/matchers/method_missing.rb:9:in `method_missing'
# ./.gems/ruby/1.8/gems/actionpack-3.0.5/lib/action_dispatch/testing/assertions/routing.rb:175:in `method_missing'
# ./spec/controllers/api/plist/providers_listing_spec.rb:19
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.6.4/lib/rspec/core/example.rb:48:in `instance_eval'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.6.4/lib/rspec/core/example.rb:48:in `run'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.6.4/lib/rspec/core/example.rb:107:in `with_around_hooks'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.6.4/lib/rspec/core/example.rb:45:in `run'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.6.4/lib/rspec/core/example_group.rb:294:in `run_examples'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.6.4/lib/rspec/core/example_group.rb:290:in `map'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.6.4/lib/rspec/core/example_group.rb:290:in `run_examples'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.6.4/lib/rspec/core/example_group.rb:262:in `run'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.6.4/lib/rspec/core/command_line.rb:24:in `run'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.6.4/lib/rspec/core/command_line.rb:24:in `map'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.6.4/lib/rspec/core/command_line.rb:24:in `run'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.6.4/lib/rspec/core/reporter.rb:12:in `report'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.6.4/lib/rspec/core/command_line.rb:21:in `run'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.6.4/lib/rspec/core/runner.rb:80:in `run_in_process'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.6.4/lib/rspec/core/runner.rb:69:in `run'`
這裏是我的測試寶石配置:
gem 'ruby-prof' # perf
gem 'rspec-rails', :git => 'git://github.com/rspec/rspec-rails.git'
gem 'shoulda' # Shoulda
gem 'factory_girl_rails' #=> mocking
gem 'capybara', :git => "http://github.com/jnicklas/capybara.git"
gem 'database_cleaner'
gem 'rb-fsevent', :require => false if RUBY_PLATFORM =~ /darwin/i #guard mac dependency
gem 'guard-livereload' # browser reloading
gem 'guard-rspec'
gem 'guard-test'
gem 'growl' #grow notification
我'm使用database_clearner來處理mongo db ...
直到現在我還沒有真正使用:
require 'spec_helper'
describe Api::Plist::ProvidersController, :type => :api do
let (:user) {Factory(:confirmed_user)}
let (:api_account) {user.new_api_account}
let (:api_token) {api_account.authentication_token}
let (:email) {api_account.email}
it "should return a successfull plist containing a list of providers" do
get 'index', :auth_token => api_token, :email => email
last_response.status.shoud be_success
last_response.body.should eql({:sucess => true}.to_plist.to_s)
end
end
這裏是我已經看過的職位,即使他們主要談webrat ...:
- http://codingfrontier.com/integration-testing-setup-with-rspec-2-and-ca
- https://github.com/rspec/rspec-rails/issues/174
- ...
如果任何人都知道該做什麼,使用哪個寶石版本?