2014-02-25 32 views
1

請幫幫忙,使用Rspec的護欄及Neo4j.rb:缺少方法

我做護欄及Neo4j的與ronge的neo4j.rb創業板的項目。我可以使用Neo4j獲得發電機和CRUD。但是,每次運行'rspec'測試時,都會在spec_helper中的RSpec配置塊內丟失錯誤。

任何人都可以幫我解決這個問題嗎?

非常感謝!

Rails和JRuby版本。

[email protected]:~/temp$ rails -v Rails 3.2.17 [email protected]:~/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

的Gemfile

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" 

然後,

[email protected]:~/test/myapp$ rails g rspec:install 
     create .rspec 
     create spec 
     create spec/spec_helper.rb 
[email protected]:~/test/myapp$ rails g model testnode 
     invoke neo4j 
     create app/models/testnode.rb 
     invoke rspec 
     create  spec/models/testnode_spec.rb 

當我運行rspec,這裏是錯誤:

[email protected]:~/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 
+2

如果按照評論中的建議移除fixture_path行會發生什麼? –

+0

完成...這已解決......實際上我追溯到rspec-rails,並發現:fixture_path是一個設置,只有當AR出現時纔會添加...所以當然這是一種缺少方法,所以:use_transactional_fixtures。對不起,我應該更仔細地追溯到源代碼。非常感謝:Ronge! –

回答

2

解決,請參閱有關問題的意見。

:fixture_path和:use_transactional_fixtures是由rspec-rails 添加的兩個設置,僅在存在ActiveRecord的情況下爲。所以當然他們缺少方法。只是評論他們,你不需要他們,如果你使用Neo4j.rb