【问题标题】:Using Rspec with Rails and Neo4j.rb: missing method将 Rspec 与 Rails 和 Neo4j.rb 一起使用:缺少方法
【发布时间】:2014-02-25 02:44:57
【问题描述】:

请帮忙,

我正在使用 ronge 的 neo4j.rb gem 做一个带有 rails 和 neo4j 的项目。我可以让生成器和 CRUD 与 Neo4j 一起工作。但是,每次我运行“rspec”测试时,spec_helper 中 RSpec 的配置块中都会出现方法缺失错误。

谁能帮我解决这个问题?

非常感谢!!

Rails 和 JRuby 版本。

saasbook@saasbook:~/temp$ rails -v Rails 3.2.17 saasbook@saasbook:~/temp$ ruby -v jruby 1.7.10 (1.9.3p392) 2014-01-09 c4ecd6b on Java HotSpot(TM) Client VM 1.7.0_51-b13 [linux-i386]

创建 Rails 应用

rails new myapp -m http://andreasronge.github.com/neo4j/rails.rb -O -T

宝石文件

source 'https://rubygems.org'
gem 'rails', '3.2.17'
gem 'jruby-openssl'
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'
  gem 'therubyrhino'
  gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'

group :development, :test do
  gem "rspec-rails"
end

gem "neo4j"

那么,

saasbook@saasbook:~/test/myapp$ rails g rspec:install
      create  .rspec
      create  spec
      create  spec/spec_helper.rb
saasbook@saasbook:~/test/myapp$ rails g model testnode
      invoke  neo4j
      create    app/models/testnode.rb
      invoke    rspec
      create      spec/models/testnode_spec.rb

当我运行rspec 时,出现以下错误:

saasbook@saasbook:~/test/myapp$ rspec
NoMethodError: undefined method `fixture_path=' for #<RSpec::Core::Configuration:0xbcf6bf>
           (root) at /home/saasbook/test/myapp/spec/spec_helper.rb:21
        configure at /home/saasbook/.rvm/gems/jruby-1.7.10/gems/rspec-core-2.14.7/lib/rspec/core.rb:120
           (root) at /home/saasbook/test/myapp/spec/spec_helper.rb:11
          require at org/jruby/RubyKernel.java:1083
           (root) at /home/saasbook/test/myapp/spec/models/testnode_spec.rb:1
             load at org/jruby/RubyKernel.java:1099
           (root) at /home/saasbook/test/myapp/spec/models/testnode_spec.rb:1
             each at org/jruby/RubyArray.java:1613
           (root) at /home/saasbook/.rvm/gems/jruby-1.7.10/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:1
  load_spec_files at /home/saasbook/.rvm/gems/jruby-1.7.10/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896
  load_spec_files at /home/saasbook/.rvm/gems/jruby-1.7.10/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896
              run at /home/saasbook/.rvm/gems/jruby-1.7.10/gems/rspec-core-2.14.7/lib/rspec/core/command_line.rb:22

另外,这里是生成的 spec_helper.rb 文件:

# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'

# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }

RSpec.configure do |config|
  # ## Mock Framework
  #
  # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
  #
  # config.mock_with :mocha
  # config.mock_with :flexmock
  # config.mock_with :rr

  # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
  config.fixture_path = "#{::Rails.root}/spec/fixtures"

  # If you're not using ActiveRecord, or you'd prefer not to run each of your
  # examples within a transaction, remove the following line or assign false
  # instead of true.
  config.use_transactional_fixtures = true

  # If true, the base class of anonymous controllers will be inferred
  # automatically. This will be the default behavior in future versions of
  # rspec-rails.
  config.infer_base_class_for_anonymous_controllers = false

  # Run specs in random order to surface order dependencies. If you find an
  # order dependency and want to debug it, you can fix the order by providing
  # the seed, which is printed after each run.
  #     --seed 1234
  config.order = "random"
end

【问题讨论】:

  • 如果按照评论中的建议删除 fixture_path 行会怎样?
  • 完成...这已解决...实际上我追溯到 rspec-rails,发现 :fixture_path 是一个只有在 AR 出现时才会添加的设置...所以当然缺少一个方法,所以也缺少:use_transactional_fixtures。很抱歉粗心大意,我应该更仔细地追溯源代码。非常感谢:荣格!

标签: ruby ruby-on-rails-3 rspec neo4j jruby


【解决方案1】:

已解决,请参阅有关问题的 cmets。

:fixture_path 和 :use_transactional_fixtures 是 rspec-rails ONLY 在 ActiveRecord 存在下添加的两个设置。所以他们当然缺少方法。把它们注释掉,如果你使用 Neo4j.rb 就不需要它们

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多