Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Rethink how RSpec and Cucumber are run in different situations

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...
commit 3c03579cbb8084cea7644db9422c82e7c7e1909a 1 parent c8e93e3
@njonsson authored
Showing with 22 additions and 13 deletions.
  1. +1 −1  .rspec
  2. +1 −1  .travis.yml
  3. +1 −1  Guardfile
  4. +19 −10 Rakefile
View
2  .rspec
@@ -1,2 +1,2 @@
--color
---format progress
+--format documentation
View
2  .travis.yml
@@ -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
View
2  Guardfile
@@ -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'
View
29 Rakefile
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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)
Please sign in to comment.
Something went wrong with that request. Please try again.