I want to avoid having to set the CLI options for each of my guardfiles' rspec sections, like so:
guard 'rspec', :cli => "--color --drb --format documentation", :version => 2 do
I took out those :cli options entirely and restarted Guard but it did not load my custom options from ~/.rspec. I do not have a .rspec dotfile in my project dir either.
Any ideas on how to link up Guard with that dotfile?
rspec_dotfile = File.expand_path("~/.rspec")
cli_options = File.exists?(rspec_dotfile) ? File.read(rspec_dotfile).chomp : "--some --default-options"
guard 'rspec', :cli => cli_options, :version => 2 do
# ...
end
Related
I want to use this gem (sitemap_generator)
sitemap_generator
To create my sitemap xml file for my site.
So i create sitemap.rb inside config folder
Then i put this code inside
require 'rubygems'
require 'sitemap_generator'
SitemapGenerator::Sitemap.default_host = 'https://xxxx.com/'
SitemapGenerator::Sitemap.create do
# add '/home', :changefreq => 'daily', :priority => 0.9
# add '/contact_us', :changefreq => 'weekly'
add '/'
add '/signup'
add '/login'
Activity.find_each do |activity|
add activity_show_path(activity.id), :lastmod => activity.created_at
end
end
SitemapGenerator::Sitemap.ping_search_engines # Not needed if you use the rake tasks
But when i run
ruby config/sitemap.rb
I always got this
uninitialized constant Activity (NameError)
So how can i fixed this
(I guess the problem from the model)
Thanks!
I always run it through the rake task, try this:
rake sitemap:refresh:no_ping
It's possible the rake task does the magic to make the application code available when that's running.
Update: probably a duplicate of Rails sitemap_generator Uninitialized Constant? (sorry I should have looked first)
I have tagged my specs that require selenium with :js => true in my spec files. What I want to achieve is that guard will always run the non :js specs first and only when these specs all pass run the specs tagged with :js.
This is my current Guardfile:
group 'non-javascript specs' do
guard 'rspec', cmd: 'zeus rspec --color --format nested --fail-fast -t ~js', parallel: false, bundler: false, :all_on_start => false, :all_after_pass => false, :keep_failed => false do
notification :terminal_notifier
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|\.jbuilder)$}) { |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/features/#{m[1]}_spec.rb"] }
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
watch('config/routes.rb') { "spec/routing" }
watch('app/controllers/application_controller.rb') { "spec/controllers" }
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
end
end
group 'javascript specs' do
guard 'rspec', cmd: 'zeus rspec --color --format nested --fail-fast -t js', parallel: false, bundler: false, :all_on_start => false, :all_after_pass => false, :keep_failed => false do
notification :terminal_notifier
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
watch(%r{^spec/requests/.+_spec\.rb$})
watch(%r{^spec/features/.+_spec\.rb$})
end
end
However, with this config it will split the execution of js and non js specs, but it will always run the js specs even if the non js specs fail.
How can I tell guard to not run the second group if the first group does not pass?
To clean things up a bit, put this in your .rspec or .rspec-local file:
--color
--format nested
--fail-fast
Solution: use halt_on_fail to stop at first group item failing:
group 'specs', halt_on_fail: true do
js_opts = { parallel: false, bundler: false, :all_on_start => false, :all_after_pass => false, :keep_failed => false }
guard 'rspec', js_opts.merge(cmd: 'zeus rspec -t ~js'), do
# (...)
end
guard 'rspec', js_opts.merge(cmd: 'zeus rspec -t js'), do
# (...)
end
end
This should work as expected. If not submit a bug issue in https://github.com/guard/guard.
Oh, and I think you want :all_after_pass => true in the first set - because you'd likely want all the fast tests to be green before even attempting the slow ones (unless the fast ones are independent, unlikely to be broken and too plenty to run all of them).
I believe the fix is to combine both groups into a single group and use && between the commands. That way, the second part of the command will only run if the first part returns true:
cmd: `zeus rspec --color --format nested --fail-fast -t ~js && zeus rspec --color --format nested --fail-fast -t js`
For more info on && see What is the purpose of "&&" in a shell command?.
I'm using guard to run all my rails specs and its awesome. I've written a bunch of request specs that use capybara and selenium to test my pages javascripts by opening firefox and they are awesome as well however they tend to be slow and pull focus away from my editor while I'm typing.
Is there a way to configure guard to not run my request specs when it runs all and maybe asign a hot key to just run the request specs?
Answering my own question incase other come across this:
rspec-rails can pass command line arguments to rspec via :cli. Additionally examples can be tagged in spec files and then rspec can be run to include or exclude those tagged examples.
Turns out I'm already tagging the examples I wanted to exclude with :js=>true, wich is how you get Selenium to fire up firefox.
describe "Post" do
it "should be able to edit a post", :js=>true do
# your test here
end
end
I made two groups in my Guardfile one for none-javascript specs with :cli => "-t ~js" and another for spec that test javascript with :cli => "-t js". I also passed in the :all_after_pass => false for the javascript group.
here is my new guard file:
group 'none-javascript specs' do
guard 'rspec', :version => 2, :cli => '-r rspec/instafail -f RSpec::Instafail -t ~js' 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|\.jbuilder)$}) { |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" }
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
end
end
group 'javascript specs' do
guard 'rspec', :version => 2, :all_after_pass => false, :cli => '-r rspec/instafail -f RSpec::Instafail -t js' do
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
watch(%r{^spec/requests/.+_spec\.rb$})
end
end
Now when I start up guard or hit return in the guard term both groups are run executing all specs.
Guard::RSpec is running, with RSpec 2!
Running all specs
Run options: exclude {:js=>true}
...
Finished in 75.78 seconds
428 examples, 0 failures, 1 pending
Guard::RSpec is running, with RSpec 2!
Running all specs
Run options: include {:js=>true}
...
Finished in 63.68 seconds
22 examples, 0 failures
After all test pass only the none-javascript examples are run.
There's an exclude option for guard-rspec. It was implemented in #23, but wasn't documented in the README. I've made a pull request to document that.
Example
guard 'rspec', :exclude => "spec/foo/**/*" # exclude files based on glob
I've got guard, spork, cucumber and rspec working away on my system. All my specs and features run nicely but one thing puzzles me.
When I run guard init spork, the Guardfile that is created contains the following:
guard 'spork', :cucumber_env => { 'RAILS_ENV' => 'cucumber' }, :rspec_env => { 'RAILS_ENV' => 'test' } do
But this causes an error because I do not have a cucumber.rb file in my enironments folder. So to get this working I change the code to
guard 'spork', :cucumber_env => { 'RAILS_ENV' => 'test' }, :rspec_env => { 'RAILS_ENV' => 'test' } do
Now my question is, why does guard/spork subsume that my application would have a cucumber.rb file in config/environments? Should I be running cucumber in it's own environment? Should I create a cucumber.rb file by hand? I'd have thought that rails g cucumber:install would have done that for me if it was so important.
Using the latest released versions of cucumber, rspec and guard-* gems
The reason is that in earlier versions of cucumber, the cucumber:install generator actually created its own cucumber environment. This is no longer the case in the later versions of the gem, but the guard-spork gem still assumes the RAILS_ENV is cucumber instead of test. I use the same gem and made the same configuration change and everything is working as I would expect.
When running script commands like script/console I get the error message:
no such file to load -- thinking-sphinx
In my evironment.rb file I have:
config.gem 'thinking-sphinx', :version => '1.3.18', :require_as => 'thinking_sphinx'
In my rake file:
require 'thinking_sphinx/tasks'
I have following versions:
gem 1.3.7
ruby 1.8.7
Rails 2.3.8
My rake commands like rake ts:rebuild work fine!
Is there a way to get rid of the annoying error message?
Tnx!!!
ps: I also use RVM
It looks like Rails is trying to require the gem as "thinking-sphinx" rather than as "thinking_sphinx". You need to use :lib to specify the require path rather than :require_as IIRC.
config.gem 'thinking-sphinx', :version => '1.3.18', :lib => 'thinking_sphinx'