1

我对 RoR 非常陌生,遵循 Michael Hartly 的 Ruby 教程并设置了 guard-rspec 后,它不会检测到正在监视的文件的更改。我进行了广泛的搜索,并且(除非我不理解某些东西——这太可能了)没有一个答案适用于我。其他一切似乎都有效。

我正在运行 Windows 8 并进行了设置,因此它应该在 Sublime Text 2 中显示测试结果。启动 Guard 时收到 2 个通知,显示我所有测试的 RSpec 结果,但这似乎是我最后一次看到它。我可以运行所有测试,但是在更改监视文件时它不会运行。

我正在更改的文件位于 C:\Sites\demo\app\views\static_pages 中,其中 \demo 是我的 rails 应用程序的根目录。

我在下面附上了我的 Gemfile 和 Guardfile。如果还有其他需要解决的问题,请告诉我。我希望我没有提供太多或太少的信息,但我真的很湿!谢谢!

宝石文件:

source 'https://rubygems.org'

gem 'rails', '3.2.13'

group :development, :test do
  gem 'sqlite3', '1.3.5'
  gem 'rspec-rails', '2.11.0'
  gem 'guard-rspec', '1.2.1'
  gem 'guard-spork', '1.2.0'
  gem 'childprocess', '0.3.6'
  gem 'spork', '0.9.2'
  gem 'listen'

end

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '3.2.5'
  gem 'coffee-rails', '3.2.2'
  gem 'uglifier', '1.2.3'
end

gem 'jquery-rails', '2.0.2'

# Test gems on Windows
group :test do
  gem 'capybara', '1.1.2'
  gem 'rb-fchange', '0.0.5'
  gem 'rb-notifu', '0.0.4'
  gem 'win32console', '1.3.0'
end

group :production do
  gem 'pg', '0.12.2'
end

保护文件:

require 'active_support/core_ext'

guard 'spork', :rspec_env => { 'RAILS_ENV' => 'test' } do
  watch('config/application.rb')
  watch('config/environment.rb')
  watch(%r{^config/environments/.+\.rb$})
  watch(%r{^config/initializers/.+\.rb$})
  watch('Gemfile')
  watch('Gemfile.lock')
  watch('spec/spec_helper.rb')
  watch('test/test_helper.rb')
  watch('spec/support/')
end

    guard 'rspec', :version => 2, :all_after_pass => false, :cli => '--drb' 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 request specs
      watch(%r{^app/views/(.+)/.*\.(erb|haml)$})          { |m| "spec/requests/#{m[1]}_spec.rb" }

      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
     end

spec_helper.rb:

require 'rubygems'
require 'spork'

Spork.prefork do
  # Loading more in this block will cause your tests to run faster. However,
  # if you change any configuration or code from libraries loaded here, you'll
  # need to restart spork for it take effect.
  # 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
    config.mock_with :rspec

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

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

end
4

0 回答 0