我用Rails 3.1,我想補充一些存根和嘲笑我的規格,但我得到一個NoMethodError:RSpec的嘲弄「未定義的方法`stub_model」爲#<類別:0x007ff9c339bd80>(NoMethodError)」
undefined method `stub_model' for #<Class:0x007ff9c339bd80> (NoMethodError)
這裏是我的Gemfile的摘錄:
gem 'rspec'
gem 'rspec-rails'
我跑捆綁安裝和軌道摹rspec的:安裝
這裏是試圖創建一個stub_model代碼
0 @flight = stub_model(Flight)
1 Flight.stub! (:all).and_return([@flight])
這裏是spec_helper.rb:
0 # This file is copied to spec/ when you run 'rails generate rspec:install'
1 ENV["RAILS_ENV"] ||= 'test'
2 require File.expand_path("../../config/environment", __FILE__)
3 require 'rspec/rails'
4
5 # Requires supporting ruby files with custom matchers and macros, etc,
6 # in spec/support/ and its subdirectories.
7 Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
8
9 RSpec.configure do |config|
10 # == Mock Framework
11 #
12 # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
13 #
14 # config.mock_with :mocha
15 # config.mock_with :flexmock
16 # config.mock_with :rr
17 config.mock_with :rspec
18
19 # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
20 config.fixture_path = "#{::Rails.root}/spec/fixtures"
21
22 # If you're not using ActiveRecord, or you'd prefer not to run each of your
23 # examples within a transaction, remove the following line or assign false
24 # instead of true.
25 config.use_transactional_fixtures = true
26 end
我打電話 「rspec的./spec」 和 「捆綁的exec rspec的./spec」(嘗試都沒有區別)
我所做的一切似乎都是教科書(實際上,我遵循Rails 3 Way)。
我錯過了什麼?
凡從叫stub_model?控制器規格?查看規格?型號規格? –
控制器規格 – hamiltop
嗯......它只是決定開始工作。我建立了一個新項目來測試行爲,並且在該項目中運行良好。然後,我再次嘗試了原始項目,並且工作正常。奇怪的。 – hamiltop