Rspec无法在现有的RailsApp中执行简单的规范

时间:2015-11-20 09:32:08

标签: ruby-on-rails ruby rspec

我在rails v4.0.9中已经存在RailsApp

我的团队开发了一些gem并在文件夹initializers

中配置了几个文件

我需要使用Rspec构建测试框架,这是我的Gemfile:

group :development, :test do
  gem "rspec-rails", "~> 3.1.0"
  gem "factory_girl_rails", "~> 4.4.1" , :require => false
end

group :test do
  gem "faker", "~> 1.4.3"
  gem "capybara", "~> 2.4.3"
  gem "database_cleaner", "~> 1.3.0"
  gem "launchy", "~> 2.4.2"
  gem "selenium-webdriver", "~> 2.43.0"
end

我刚尝试构建Model Spec,名称模型是cart,首先我输入非常简单的规范,只是为了使得Rspec正确运行:

require 'rails_helper'

describe Cart do
    it "has a valid factory for Cart"
end

spec/factories/cart.rb

FactoryGirl.define do
    factory :cart do
        user_id { Faker::Number.number(3) }
    end
end

当我输入控制台rspec spec/models/cart_spec.rb时:

config/initializers/cassandra.rb:25:in `initialize': undefined method `[]' for nil:NilClass (NoMethodError)
    from config/initializers/cassandra.rb:59:in `new'
    from config/initializers/cassandra.rb:59:in `block in <top (required)>'
    from lib/cassandra_utils/connector.rb:13:in `configure'
    from config/initializers/cassandra.rb:58:in `<top (required)>'
    from .rvm/gems/ruby-2.1.5/gems/activesupport-4.0.9/lib/active_support/dependencies.rb:223:in `load'
    from .rvm/gems/ruby-2.1.5/gems/activesupport-4.0.9/lib/active_support/dependencies.rb:223:in `block in load'
    from .rvm/gems/ruby-2.1.5/gems/activesupport-4.0.9/lib/active_support/dependencies.rb:214:in `load_dependency'
    from .rvm/gems/ruby-2.1.5/gems/activesupport-4.0.9/lib/active_support/dependencies.rb:223:in `load'

我怎么解决这个问题?

THX

1 个答案:

答案 0 :(得分:1)

ENV['IC_CONTACT_POINTS']

返回falsey值,因此评估cassandra_config['IC_CONTACT_POINTS']

cassandra_confignil。修改它,你就没事了。