0

我在 Michael Hartl 的教程的帮助下学习 Ruby on Rails。我开始做这部分。我做了添加守卫,一切似乎都很好。然后我继续尝试执行 Spork 进程,在按照所有说明进行操作后,当我运行 `guard' 时,这就是我得到的:

16:57:46 - INFO - Guard here! It looks like your project has a Gemfile, yet you are running
> [#] `guard` outside of Bundler. If this is your intent, feel free to ignore this
> [#] message. Otherwise, consider using `bundle exec guard` to ensure your
> [#] dependencies are loaded correctly.
> [#] (You can run `guard` with --no-bundler-warning to get rid of this message.)
16:57:46 - INFO - Guard is using TerminalTitle to send notifications.
16:57:46 - INFO - Guard::RSpec is running
16:57:46 - INFO - Running all specs
No DRb server is running. Running in local process instead ...
/Users/siaW/Desktop/pwr/spec/spec_helper.rb:30:in `block (2 levels) in <top (required)>': undefined method `fixture_path=' for #<RSpec::Core::Configuration:0x007fd2eb836b50> (NoMethodError)
    from /Users/siaW/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core.rb:107:in `configure'
    from /Users/siaW/Desktop/pwr/spec/spec_helper.rb:20:in `block in <top (required)>'
    from /Users/siaW/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/spork-1.0.0rc4/lib/spork.rb:24:in `prefork'
    from /Users/siaW/Desktop/pwr/spec/spec_helper.rb:6:in `<top (required)>'
    from /Users/siaW/Desktop/pwr/spec/requests/static_pages_spec.rb:1:in `require'
    from /Users/siaW/Desktop/pwr/spec/requests/static_pages_spec.rb:1:in `<top (required)>'
    from /Users/siaW/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load'
    from /Users/siaW/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `block in load_spec_files'
    from /Users/siaW/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `each'
    from /Users/siaW/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load_spec_files'
    from /Users/siaW/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:22:in `run'
    from /Users/siaW/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:77:in `rescue in run'
    from /Users/siaW/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:73:in `run'
    from /Users/siaW/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:17:in `block in autorun'

16:57:49 - INFO - Guard::RSpec is running
16:57:49 - INFO - Running all specs
No DRb server is running. Running in local process instead ...
/Users/siaW/Desktop/pwr/spec/spec_helper.rb:30:in `block (2 levels) in <top (required)>': undefined method `fixture_path=' for #<RSpec::Core::Configuration:0x007fa9cbc54028> (NoMethodError)
    from /Users/siaW/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core.rb:107:in `configure'
    from /Users/siaW/Desktop/pwr/spec/spec_helper.rb:20:in `block in <top (required)>'
    from /Users/siaW/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/spork-1.0.0rc4/lib/spork.rb:24:in `prefork'
    from /Users/siaW/Desktop/pwr/spec/spec_helper.rb:6:in `<top (required)>'
    from /Users/siaW/Desktop/pwr/spec/requests/static_pages_spec.rb:1:in `require'
    from /Users/siaW/Desktop/pwr/spec/requests/static_pages_spec.rb:1:in `<top (required)>'
    from /Users/siaW/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load'
    from /Users/siaW/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `block in load_spec_files'
    from /Users/siaW/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `each'
    from /Users/siaW/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load_spec_files'
    from /Users/siaW/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:22:in `run'
    from /Users/siaW/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:77:in `rescue in run'
    from /Users/siaW/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:73:in `run'
    from /Users/siaW/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:17:in `block in autorun'

16:57:51 - INFO - Guard::RSpec is running
16:57:51 - INFO - Running all specs
No DRb server is running. Running in local process instead ...
/Users/siaW/Desktop/pwr/spec/spec_helper.rb:30:in `block (2 levels) in <top (required)>': undefined method `fixture_path=' for #<RSpec::Core::Configuration:0x007f9f9a846f20> (NoMethodError)
    from /Users/siaW/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core.rb:107:in `configure'
    from /Users/siaW/Desktop/pwr/spec/spec_helper.rb:20:in `block in <top (required)>'
    from /Users/siaW/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/spork-1.0.0rc4/lib/spork.rb:24:in `prefork'
    from /Users/siaW/Desktop/pwr/spec/spec_helper.rb:6:in `<top (required)>'
    from /Users/siaW/Desktop/pwr/spec/requests/static_pages_spec.rb:1:in `require'
    from /Users/siaW/Desktop/pwr/spec/requests/static_pages_spec.rb:1:in `<top (required)>'
    from /Users/siaW/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load'
    from /Users/siaW/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `block in load_spec_files'
    from /Users/siaW/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `each'
    from /Users/siaW/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load_spec_files'
    from /Users/siaW/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:22:in `run'
    from /Users/siaW/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:77:in `rescue in run'
    from /Users/siaW/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:73:in `run'
    from /Users/siaW/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:17:in `block in autorun'

16:57:53 - INFO - Guard is now watching at '/Users/siaW/Desktop/pwr'

我知道我做错了什么,但作为一个新手,我无法准确指出我做错了什么。我已经做了很多谷歌搜索,并在 StackOverflow 上查看了一些解决方案,但到目前为止所有的努力都是徒劳的。我只想撤消 Spork 进程,让一切都像以前一样顺利。我想我可能不得不跳过 Spork,因为现在它对我来说太先进了。

我的宝石文件:

source 'https://rubygems.org'
ruby '2.0.0'
#check and remove below if not relevant
#ruby-gemset=railstutorial_rails_4_0

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

group :development, :test do
  gem 'sqlite3', '1.3.8'
  gem 'rspec-rails', '2.13.1'
  gem 'guard-rspec', '2.5.0'
  gem 'spork-rails', '4.0.0'
  gem 'guard-spork', '1.5.0'
  gem 'childprocess', '0.3.6'
end

group :test do
  gem 'selenium-webdriver', '2.35.1'
  gem 'capybara', '2.1.0'
  gem 'growl', '1.0.3'
end

# Use sqlite3 as the database for Active Record
#gem 'sqlite3'

# Use SCSS for stylesheets
gem 'sass-rails', '4.0.1'

# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '2.1.1'

# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '4.0.1'

# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails', '3.0.4'

# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks', '1.1.1'

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '1.0.2'

group :doc do
  gem 'sdoc', '0.3.20', require: false
end

group :production do
  gem 'pg', '0.15.1'
  gem 'rails_12factor', '0.0.2'
end



# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.1.2'

# Use unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano', group: :development

# Use debugger
# gem 'debugger', group: [:development, :test]

我的保护文件:

# A sample Guardfile
# More info at https://github.com/guard/guard#readme
require 'active_support/inflector'



guard 'rspec', all_after_pass: false do
  watch(%r{^spec/.+_spec\.rb$})
  watch(%r{^lib/(.+)\.rb$})     { |m| "spec/lib/#{m[1]}_spec.rb" }
  watch('spec/spec_helper.rb')  { "spec" }

  # Rails example
  watch(%r{^app/(.+)\.rb$})                           { |m| "spec/#{m[1]}_spec.rb" }
  watch(%r{^app/(.*)(\.erb|\.haml)$})                 { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
  watch(%r{^app/controllers/(.+)_(controller)\.rb$})  { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
  watch(%r{^spec/support/(.+)\.rb$})                  { "spec" }
  watch('config/routes.rb')                           { "spec/routing" }
  watch('app/controllers/application_controller.rb')  { "spec/controllers" }

  # Capybara features specs
  watch(%r{^app/views/(.+)/.*\.(erb|haml)$})          { |m| "spec/features/#{m[1]}_spec.rb" }

  # Turnip features and steps
  watch(%r{^spec/acceptance/(.+)\.feature$})
  watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$})   { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }


  watch('config/routes.rb')
    # Rails mastering
    watch(%r{^app/controllers/(.+)_(controller)\.rb$}) do |m|
      ["spec/routing/#{m[1]}_routing_spec.rb",
       "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb",
       "spec/acceptance/#{m[1]}_spec.rb",
       (m[1][/_pages/] ? "spec/requests/#{m[1]}_spec.rb" :
                         "spec/requests/#{m[1].singularize}_pages_spec.rb")]
    end
    watch(%r{^app/views/(.+)/}) do |m|
      (m[1][/_pages/] ? "spec/requests/#{m[1]}_spec.rb" :
                        "spec/requests/#{m[1].singularize}_pages_spec.rb")
    end
    watch(%r{^app/controllers/sessions_controller\.rb$}) do |m|
      "spec/requests/authentication_pages_spec.rb"
    end
end


guard 'rspec' do
  watch(%r{^spec/.+_spec\.rb$})
  watch(%r{^lib/(.+)\.rb$})     { |m| "spec/lib/#{m[1]}_spec.rb" }
  watch('spec/spec_helper.rb')  { "spec" }

  # Rails example
  watch(%r{^app/(.+)\.rb$})                           { |m| "spec/#{m[1]}_spec.rb" }
  watch(%r{^app/(.*)(\.erb|\.haml)$})                 { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
  watch(%r{^app/controllers/(.+)_(controller)\.rb$})  { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
  watch(%r{^spec/support/(.+)\.rb$})                  { "spec" }
  watch('config/routes.rb')                           { "spec/routing" }
  watch('app/controllers/application_controller.rb')  { "spec/controllers" }

  # Capybara features specs
  watch(%r{^app/views/(.+)/.*\.(erb|haml)$})          { |m| "spec/features/#{m[1]}_spec.rb" }

  # Turnip features and steps
  watch(%r{^spec/acceptance/(.+)\.feature$})
  watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$})   { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
end


guard 'rspec' do
  watch(%r{^spec/.+_spec\.rb$})
  watch(%r{^lib/(.+)\.rb$})     { |m| "spec/lib/#{m[1]}_spec.rb" }
  watch('spec/spec_helper.rb')  { "spec" }

  # Rails example
  watch(%r{^app/(.+)\.rb$})                           { |m| "spec/#{m[1]}_spec.rb" }
  watch(%r{^app/(.*)(\.erb|\.haml)$})                 { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
  watch(%r{^app/controllers/(.+)_(controller)\.rb$})  { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
  watch(%r{^spec/support/(.+)\.rb$})                  { "spec" }
  watch('config/routes.rb')                           { "spec/routing" }
  watch('app/controllers/application_controller.rb')  { "spec/controllers" }

  # Capybara features specs
  watch(%r{^app/views/(.+)/.*\.(erb|haml)$})          { |m| "spec/features/#{m[1]}_spec.rb" }

  # Turnip features and steps
  watch(%r{^spec/acceptance/(.+)\.feature$})
  watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$})   { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
end

我也确实bundle exec spork --bootstrap在终端中运行了这个命令。我的spec_helper.rb样子是这样的:

require 'rubygems'
require 'spork'
#uncomment the following line to use spork with the debugger
#require 'spork/ext/ruby-debug'

Spork.prefork do
  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}

  # Checks for pending migrations before tests are run.
  # If you are not using ActiveRecord, you can remove this line.
  ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)

  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"
    config.include Capybara::DSL
  end
end

Spork.each_run do
  # This code will be run each time you run your specs.

end

# --- Instructions ---
# Sort the contents of this file into a Spork.prefork and a Spork.each_run
# block.
#
# The Spork.prefork block is run only once when the spork server is started.
# You typically want to place most of your (slow) initializer code in here, in
# particular, require'ing any 3rd-party gems that you don't normally modify
# during development.
#
# The Spork.each_run block is run each time you run your specs.  In case you
# need to load files that tend to change during development, require them here.
# With Rails, your application modules are loaded automatically, so sometimes
# this block can remain empty.
#
# Note: You can modify files loaded *from* the Spork.each_run block without
# restarting the spork server.  However, this file itself will not be reloaded,
# so if you change any of the code inside the each_run block, you still need to
# restart the server.  In general, if you have non-trivial code in this file,
# it's advisable to move it into a separate file so you can easily edit it
# without restarting spork.  (For example, with RSpec, you could move
# non-trivial code into a file spec/support/my_helper.rb, making sure that the
# spec/support/* files are require'd from inside the each_run block.)
#
# Any code that is left outside the two blocks will be run during preforking
# *and* during each_run -- that's probably not what you want.
#
# These instructions should self-destruct in 10 seconds.  If they don't, feel
# free to delete them.




# 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 }

# Checks for pending migrations before tests are run.
# If you are not using ActiveRecord, you can remove this line.
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)

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"
  config.include Capybara::DSL
end
4

2 回答 2

0

这是一个已知问题- 请尝试按照此处的步骤操作

于 2013-11-05T18:54:42.817 回答
0

在您发布的 spec_helper.rb 文件中,后面的文本块

ENV["RAILS_ENV"] ||= 'test'

包含两次。您已将该部分移动到“Spork.prefork do”中,但在长指令注释之后再次重复。移动时是否不小心复制而不是剪切?

在此之后尝试从 spec_helper.rb 文件中删除所有内容:

Spork.each_run do
  # This code will be run each time you run your specs.
end
# delete everything from here...
于 2013-11-15T20:32:19.337 回答