2016-09-17 99 views
4

在我的Rails 5.0.0應用程序,我已經添加了以下到我的Gemfile:Rails的5 - 找不到發電機 'rspec的:安裝'

group :development, :test do 
    gem 'byebug', platform: :mri 
    gem 'rspec-rails', '~> 3.5', '>= 3.5.2' 
end 

我跑bundle install。然後,寶石已成功安裝。

然後我跑了以下內容:

rails generate rspec:install 

但我得到一個錯誤說:

Running via Spring preloader in process 8893 
Could not find generator 'rspec:install'. Maybe you meant 'css:assets', 'assets' or 'scaffold' 
Run `rails generate --help` for more options. 

有上發佈這個錯誤(Could not find generator 'rspec:install')其他問題一大堆, 但他們都不爲我工作,它看起來像我有一個不同的問題。

櫃面的需要,這是我bundle show輸出:

Gems included by the bundle: 
    * actioncable (5.0.0.1) 
    * actionmailer (5.0.0.1) 
    * actionpack (5.0.0.1) 
    * actionview (5.0.0.1) 
    * activejob (5.0.0.1) 
    * activemodel (5.0.0.1) 
    * activerecord (5.0.0.1) 
    * activesupport (5.0.0.1) 
    * arel (7.1.2) 
    * builder (3.2.2) 
    * bundler (1.12.5) 
    * byebug (9.0.5) 
    * coffee-rails (4.2.1) 
    * coffee-script (2.4.1) 
    * coffee-script-source (1.10.0) 
    * concurrent-ruby (1.0.2) 
    * debug_inspector (0.0.2) 
    * diff-lcs (1.2.5) 
    * erubis (2.7.0) 
    * execjs (2.7.0) 
    * ffi (1.9.14) 
    * globalid (0.3.7) 
    * i18n (0.7.0) 
    * jbuilder (2.6.0) 
    * jquery-rails (4.2.1) 
    * listen (3.0.8) 
    * loofah (2.0.3) 
    * mail (2.6.4) 
    * method_source (0.8.2) 
    * mime-types (3.1) 
    * mime-types-data (3.2016.0521) 
    * mini_portile2 (2.1.0) 
    * minitest (5.9.0) 
    * multi_json (1.12.1) 
    * nio4r (1.2.1) 
    * nokogiri (1.6.8) 
    * pkg-config (1.1.7) 
    * puma (3.6.0) 
    * rack (2.0.1) 
    * rack-test (0.6.3) 
    * rails (5.0.0.1) 
    * rails-dom-testing (2.0.1) 
    * rails-html-sanitizer (1.0.3) 
    * railties (5.0.0.1) 
    * rake (11.2.2) 
    * rb-fsevent (0.9.7) 
    * rb-inotify (0.9.7) 
    * rspec-core (3.5.3) 
    * rspec-expectations (3.5.0) 
    * rspec-mocks (3.5.0) 
    * rspec-rails (3.5.2) 
    * rspec-support (3.5.0) 
    * sass (3.4.22) 
    * sass-rails (5.0.6) 
    * spring (1.7.2) 
    * spring-watcher-listen (2.0.0) 
    * sprockets (3.7.0) 
    * sprockets-rails (3.2.0) 
    * sqlite3 (1.3.11) 
    * thor (0.19.1) 
    * thread_safe (0.3.5) 
    * tilt (2.0.5) 
    * turbolinks (5.0.1) 
    * turbolinks-source (5.0.0) 
    * tzinfo (1.2.2) 
    * uglifier (3.0.2) 
    * web-console (3.3.1) 
    * websocket-driver (0.6.4) 
    * websocket-extensions (0.1.2) 

回答

11

原來的問題,在我的情況spring寶石。重新開始的春天解決了這個問題。

第一次運行bin/spring status。如果春天正在運行,你會得到類似的東西:

Spring is running: 

    8774 spring server | chessboard | started 14 mins ago 
    8808 spring app | chessboard 6.52.08 PM | started 12 mins ago | development mode 

這意味着你必須通過運行停止春:

bin/spring stop 

然後再次啓動它:

bin/spring server 

然後運行rails generate rspec:install和它應該工作。您可能需要運行bundle update

+1

太棒了!這個答案最終指出,Spring服務器運行阻止生成器(不僅僅是Rspec)可用於'rails generate'命令。 – Glutexo

+1

我有這個問題,但只是停止/重新啓動spring是不夠的,需要在停止彈簧後運行「bundle update」。然後發電機工作。 – Sujimichi

+1

@Sujimichi根據你的評論更新了答案 –

0

今天我面臨同樣的問題,事實證明我忘了在我的Gemfile中添加rspec gem。

在Gemfile中添加以下行解決了問題。

寶石 「RSpec的護欄」

需要爲基礎做同樣的(rails g foundation:install Y

寶石 '的基礎護欄'

一旦添加運行bundle更新依賴關係。

無需重新啓動彈簧。