LoadError:无法加载此类文件 - ... / advertisement_controller_spec.rb

时间:2017-02-06 01:44:10

标签: ruby-on-rails ruby ruby-on-rails-4 rspec rspec-rails

更新:我已经添加了控制器我测试和我的宝石文件

我在这个控制器上运行测试,我得到了这个LoadError,我无法弄清楚它来自哪里。我在我的应用程序中运行了其他测试,所以我非常确定rspec运行正常。

其他一些可能相关的问题:当我第一次启动我的rails服务器时,终端返回

  

无法在任何来源中找到正确版本的栏杆(4.2.5)运行套件安装'安装缺少的宝石。

我运行了bundle install并且终端返回了

  

安装pg(0.18.4)时发生错误,Bundler无法继续。确保gem安装pg -v' 0.18.4'在捆绑之前成功。

非常感谢任何帮助!

控制器规范:

require 'rails_helper'
include RandomData

RSpec.describe AdvertisementsController, type: :controller do

  let (:my_ad) do
    Advertisement.create(
    id: 1,
    title: RandomData.random_sentence,
    copy: RandomData.random_paragraph,
    price: 99
    )
  end

  describe "GET #index" do
    it "returns http success" do
      get :index
      expect(response).to have_http_status(:success)
    end

    it "assigns [my_ad] to @advertisements" do
      get :index
      expect(assigns(:advertisements)).to eq([my_ad])
    end
  end

end

堆栈追踪:

4DV3R54RYs-MBP:Development D35TR0Y3R$ rspec spec/controllers/advertisement_controller_spec.rb
/Users/a666/.rvm/gems/ruby-2.3.3/gems/rspec-core-3.5.3/lib/rspec/core/configuration.rb:1435:in load: cannot load such file -- /Users/a666/Development/spec/controllers/advertisement_controller_spec.rb (LoadError)
    from /Users/a666/.rvm/gems/ruby-2.3.3/gems/rspec-core-3.5.3/lib/rspec/core/configuration.rb:1435:in block in load_spec_files
    from /Users/a666/.rvm/gems/ruby-2.3.3/gems/rspec-core-3.5.3/lib/rspec/core/configuration.rb:1433:in each
    from /Users/a666/.rvm/gems/ruby-2.3.3/gems/rspec-core-3.5.3/lib/rspec/core/configuration.rb:1433:in load_spec_files
    from /Users/a666/.rvm/gems/ruby-2.3.3/gems/rspec-core-3.5.3/lib/rspec/core/runner.rb:100:in setup
    from /Users/a666/.rvm/gems/ruby-2.3.3/gems/rspec-core-3.5.3/lib/rspec/core/runner.rb:86:in run
    from /Users/a666/.rvm/gems/ruby-2.3.3/gems/rspec-core-3.5.3/lib/rspec/core/runner.rb:71:in run
    from /Users/a666/.rvm/gems/ruby-2.3.3/gems/rspec-core-3.5.3/lib/rspec/core/runner.rb:45:in invoke
    from /Users/a666/.rvm/gems/ruby-2.3.3/gems/rspec-core-3.5.3/exe/rspec:4:in <top (required)>
    from /Users/a666/.rvm/gems/ruby-2.3.3/bin/rspec:22:in load
    from /Users/a666/.rvm/gems/ruby-2.3.3/bin/rspec:22:in <main>
    from /Users/a666/.rvm/gems/ruby-2.3.3/bin/ruby_executable_hooks:15:in eval
    from /Users/a666/.rvm/gems/ruby-2.3.3/bin/ruby_executable_hooks:15:in <main>

控制器:

class AdvertisementsController < ApplicationController
  def index
  end

  def show
  end

  def new
  end

  def create
  end
end

的Gemfile:

source 'https://rubygems.org'

 # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
 gem 'rails', '4.2.5'

 # #1
 group :production do
   gem 'pg'
   gem 'rails_12factor'
 end

 # #2
 group :development do
   gem 'sqlite3'
 end

 group :development, :test do
   gem 'rspec-rails', '~> 3.0'
 end

 # Use SCSS for stylesheets
 gem 'sass-rails', '~> 5.0'
 # Use Uglifier as compressor for JavaScript assets
 gem 'uglifier', '>= 1.3.0'
 # Use CoffeeScript for .coffee assets and views
 gem 'coffee-rails', '~> 4.1.0'
 # Use jquery as the JavaScript library
 gem 'jquery-rails'
 gem 'turbolinks'
 gem 'bootstrap-sass'
 gem 'pry-rails'

1 个答案:

答案 0 :(得分:0)

文件名似乎是单数advertisement_controller_spec.rb,而spec类名AdvertisementsController似乎是复数。检查您是否引用了正确的文件名。