Skip to content

Commit

Permalink
Rethink how RSpec and Cucumber are run in different situations
Browse files Browse the repository at this point in the history
The Guard configuration runs specs and features with debugger support
(specs only) and with progress-style output omitting exception
backtraces.

The 'test' Rake tasks run specs and features without debugger support
and with progress-style output, including a backtrace when exceptions
occur. The `rake test` command is invoked by `gem test` also in Travis
CI builds.

The 'spec' and 'features' Rake tasks run specs and features with
debugger support (specs only) and with documentation-style output
omitting exception backtraces.

The `spec` and `cucumber` commands run specs and features with debugger
support (specs only) and with documentation-style output omitting
exception backtraces.
  • Loading branch information
njonsson committed Nov 16, 2013
1 parent 5337339 commit d226a27
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .rspec
@@ -1,2 +1,2 @@
--color
--format progress
--format documentation
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -13,7 +13,7 @@ rvm:
- rbx-18mode
- rbx-19mode
- rbx-head
script: "bundle exec rake"
script: "bundle exec rake test"
matrix:
allow_failures:
- rvm: ruby-head
Expand Down
2 changes: 1 addition & 1 deletion Guardfile
Expand Up @@ -3,7 +3,7 @@ interactor :off
guard :rspec, :all_after_pass => true,
:all_on_start => false,
:keep_failed => false,
:cmd => "bundle exec rspec --debug #{File.read('.rspec').chomp.gsub "\n", ' '}" do
:cmd => "bundle exec rspec --debug --format progress" do
# Run the corresponding spec (or all specs) when code changes.
watch(%r{^lib/(.+)\.rb$}) do |match|
Dir["spec/#{match[1]}_spec.rb"].first || 'spec'
Expand Down
29 changes: 19 additions & 10 deletions Rakefile
Expand Up @@ -18,7 +18,16 @@ end
def define_features_task(name, options)
Cucumber::Rake::Task.new name, options[:desc] do |t|
t.bundler = false
t.cucumber_opts = options[:cucumber_opts] if options.key?(:cucumber_opts)

cucumber_opts = [t.cucumber_opts]
cucumber_opts << "--backtrace" if options[:backtrace]
if options.key?(:format)
cucumber_opts << "--format #{options[:format]}"
else
cucumber_opts << '--format pretty'
end
cucumber_opts << "--tags #{options[:tags]}" if options.key?(:tags)
t.cucumber_opts = cucumber_opts.join(' ')
end
end

Expand All @@ -27,16 +36,14 @@ tags = `grep -Ehr "^\\s*@\\S+\\s*$" features`.split("\n").
uniq.
sort
options = {:desc => 'Test features'}
options[:cucumber_opts] = '--format progress'
options[:cucumber_opts] += ' --tags @focus' if tags.delete('@focus')
options[:tags] = '@focus' if tags.delete('@focus')
define_features_task :features, options

unless tags.empty?
namespace :features do
tags.each do |t|
define_features_task t.gsub(/^@/, ''),
:desc => "Test features tagged #{t}",
:cucumber_opts => "--tags #{t}"
:desc => "Test features tagged #{t}", :tags => t
end
end
end
Expand All @@ -45,6 +52,7 @@ def define_spec_task(name, options={})
desc options[:desc]
RSpec::Core::RakeTask.new name do |t|
t.rspec_opts ||= []
t.rspec_opts << "--backtrace" if options[:backtrace]
unless options[:debug] == false
available = %w(debugger ruby-debug).detect do |debugger_library|
begin
Expand All @@ -62,6 +70,7 @@ def define_spec_task(name, options={})
$stderr.puts Cape::XTerm.bold('*** Debugging tools not installed')
end
end
t.rspec_opts << "--format #{options[:format]}" if options.key?(:format)
t.pattern = options[:pattern] || %w(spec/*_spec.rb spec/**/*_spec.rb)
end
end
Expand All @@ -81,11 +90,11 @@ task :default => [:spec, :features]

# Support the 'gem test' command.
namespace :test do
define_spec_task :spec, :desc => '', :debug => false
define_spec_task :spec, :desc => '', :backtrace => true,
:debug => false,
:format => :progress

Cucumber::Rake::Task.new :features, '' do |t|
t.bundler = false
t.cucumber_opts = '--backtrace --format progress'
end
define_features_task :features, :desc => '', :backtrace => true,
:format => :progress
end
task :test => %w(test:spec test:features)

0 comments on commit d226a27

Please sign in to comment.