2013-11-21 73 views
0

我有一個非常基本的Rspec代碼的問題,與問題'未定義的方法'獲得''相同的問題。未定義的方法'get'與Rspec

但在我的情況下,沒有任何解決方案給我工作!

我有我的Rspec的代碼在「/ RailsProject /規格/控制器」,代碼爲:

require "../spec_helper" 
describe "ApiMobile", :type => :controller do 
    it "Log In" do 
     get 'apiMobile/v0/logIn/test' 
     expect(response).to be_success 
    end 
end 

正如你可以看到我已經照着所有的說明,但我仍然有問題:

1) ApiMobile Log In 
Failure/Error: get 'apiMobile/v0/logIn/test' 
NoMethodError: 
    undefined method `get' for #<RSpec::Core::ExampleGroup::Nested_1:0x000000023b5ec8> 
# ./api_mobile_controller_spec.rb:6:in `block (2 levels) in <top (required)>' 
Finished in 0.00056 seconds 
1 example, 1 failure 

我錯過了什麼或類似的東西?

謝謝!

+0

確保在獲得將控制器方法指定爲符號後,在您的規範助手 –

+0

中需要'rspec/rails'。對於定義規範的理想方式,請參閱https://www.relishapp.com/rspec/rspec-rails/docs/controller-specs –

+0

這樣做會引發一個新錯誤:'require':無法加載此類文件 - rails/rspec(LoadError) –

回答

0

我終於發現發生了什麼:Peter Alfvin說得對,錯在於isntallation。

我在Gemfile'gem rspec'和命令行中添加'bundle install'後輸入'rspec --init'。但我還需要添加gem'rspec-rails'並鍵入'rails generate rspec:install'。

現在獲得命令的作品(我有另一個錯誤,但我認爲這是相關的路線)。

相關問題