简体   繁体   English

Guard规范/ JavaScript测试仅在第一次运行测试

[英]Guard spec/javascripts tests only run tests the first time

I am trying to get guard to work with Jasmine tests. 我试图让自己从事茉莉花测试。 I have tried guard-jasmine with jasminerice, guard-jasmine with jasmine-rails, and teaspoon. 我试过用茉莉和茉莉花护栏搭配茉莉,茉莉花和茶匙。 I end up getting the same error - the tests work the first time I set up guard, but every time I save a spec file or a javascript file the tests do not update. 我最终遇到了同样的错误-第一次设置防护后,测试便会生效,但每次保存规范文件或JavaScript文件时,测试均不会更新。 This is true when I run the tests in guard, or if I run it in a browser (ie /jasmine for jasmine-rails or /teaspoon for teaspoon), the tests work when I run rails s, but do not update the tests when I save them and refresh the page. 当我在守护程序中运行测试时,或者在浏览器中运行测试时(例如,对于茉莉花轨道,使用/ jasmine;对于茶匙,运行/ teaspoon),这都是正确的;当我运行rails时,测试可以工作,但在运行时不更新测试我保存它们并刷新页面。

I only see this behavior in my spec/javascripts directory, when I run a test in like spec/controllers, guard works as expected. 我只能在spec / javascripts目录中看到此行为,当我在诸如spec / controllers的环境中运行测试时,防护功能会按预期工作。

Any suggestions on what might be the problem? 关于可能是什么问题的任何建议?

Here is my Guardfile: 这是我的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

Thank you, 谢谢,

Change 更改

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM