【问题标题】:Guard spec/javascripts tests only run tests the first timeGuard spec/javascripts 测试只在第一次运行测试
【发布时间】:2013-10-05 00:27:53
【问题描述】:

我正试图让警卫使用 Jasmine 测试。我试过用茉莉花保护茉莉花,用茉莉花轨和茶匙保护茉莉花。我最终得到了同样的错误——测试在我第一次设置警卫时工作,但每次我保存一个规范文件或一个 javascript 文件时,测试都不会更新。当我在警卫中运行测试时,这是真的,或者如果我在浏览器中运行它(即 /jasmine 用于 jasmine-rails 或 /teaspoon 用于茶匙),当我运行 rails s 时测试工作,但不更新测试我保存它们并刷新页面。

我只在我的 spec/javascripts 目录中看到这种行为,当我在 spec/controllers 中运行测试时,guard 会按预期工作。

对可能出现的问题有什么建议吗?

这是我的 Guardfile:

# A sample Guardfile
# More info at https://github.com/guard/guard#readme

guard 'livereload' do
  watch(%r{app/views/.+\.(erb|haml|slim)$})
  watch(%r{app/helpers/.+\.rb})
  watch(%r{config/locales/.+\.yml})
  # Rails Assets Pipeline
  watch(%r{(app|vendor)(/assets/\w+/(.+\.(css|js|html|sass))).*}) { |m| "/assets/#{m[3]}" }
end

guard :teaspoon do
  # Implementation files
  watch(%r{app/assets/javascripts/(.+).js}) { |m| "#{m[1]}_spec" }

  # Specs / Helpers
  watch(%r{spec/javascripts/(.*)})
end

guard 'rspec', all_after_pass: false, all_on_start: false, bundler: true, cli: "--color --format=doc" 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('config/routes.rb')                           { "spec/routing" }
  watch('app/controllers/application_controller.rb')  { "spec/controllers" }
  watch(%r{^app/views/(.+)/}) { |m| "spec/requests/#{m[1]}_spec.rb" }

  # Capybara request specs
  #watch(%r{^app/views/(.+)/.*\.(erb|haml)$})          { |m| "spec/requests/#{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、guard-teaspoon 和 qunit 时遇到了同样的问题。您是否有可以提供的测试或规范帮助文件?你的 teaspoon_env.rb 文件是什么样的?
  • 这可能没什么用,但我停止使用茶匙和导轨来服务网站。我现在更喜欢使用 rails 来提供 API 并使用 [yeoman](yeoman.io) 来构建我的前端,作为两个不同的应用程序。

标签: ruby-on-rails jasmine guard teaspoon


【解决方案1】:

改变

watch(%r{app/assets/javascripts/(.+).js}) { |m| "#{m[1]}_spec" }

watch(%r{app/assets/javascripts/(.+).js}) { |m| "#{m[1]}_spec.js" }

【讨论】:

    猜你喜欢
    • 2013-10-30
    • 1970-01-01
    • 2017-10-19
    • 1970-01-01
    • 2021-11-13
    • 2021-03-19
    • 1970-01-01
    • 1970-01-01
    • 2017-12-27
    相关资源
    最近更新 更多