guard-rspec没有检测到变化

时间:2013-06-11 22:45:49

标签: ruby-on-rails ruby rspec guard

我是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。如果还有其他需要解决这个问题,请告诉我。我希望我没有提供太多或太少的信息,但我真的在耳朵后面湿了!谢谢!

的Gemfile:

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

Guardfile:

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

0 个答案:

没有答案