Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

0.1.8 - Rake tasks and runner improvements

  • Loading branch information...
commit 488d13452e7a5919545def34d32a81c09705a329 1 parent 4d43184
Josep M. Bach authored
14 Readme.md
View
@@ -15,6 +15,7 @@ development.
* Mocks (message expectations) with _optionally_ stubbable return values
* Nested example groups (declare them with either describe or context)
* Pending examples
+* A rake task to run the specs
* Matchers (use with object.must or object.must_not)
eq() / eql()
@@ -30,6 +31,19 @@ development.
##Usage
+In your Gemfile:
+
+ gem 'stendhal'
+
+If you want the :spec task, in your Rakefile:
+
+ require 'stendhal'
+ Stendhal::RakeTask.new
+
+ task :default => :spec
+
+##Syntax
+
# your spec file for some class - foo_spec.rb
describe "Foo" do
109 features/cli.feature
View
@@ -0,0 +1,109 @@
+Feature: Command line interpreter
+
+ Stendhal runs by default all *_spec.rb files inside a spec/ folder,
+ unless you specify which specs have to be runned.
+
+ Scenario: with no arguments
+ Given a directory named "stendhal_project"
+ And I cd to "stendhal_project"
+ And a directory named "spec"
+ And a directory named "spec/nested"
+ Given a file named "spec/sample_spec.rb" with:
+ """
+ describe "something" do
+ it "does something" do
+ # put your code here
+ end
+ end
+ """
+ And a file named "spec/another_sample_spec.rb" with:
+ """
+ describe "something" do
+ it "does something" do
+ # put your code here
+ end
+ end
+ """
+ And a file named "spec/nested/a_nested_spec.rb" with:
+ """
+ describe "something" do
+ it "does something" do
+ # put your code here
+ end
+ end
+ """
+ When I run "stendhal"
+ Then the exit status should be 0
+ And the output should contain "3 examples, 0 failures"
+
+ Scenario: specifying files to be run
+ Given a directory named "stendhal_project"
+ And I cd to "stendhal_project"
+ And a directory named "spec"
+ And a directory named "spec/nested"
+ Given a file named "spec/sample_spec.rb" with:
+ """
+ describe "something" do
+ it "does something" do
+ # put your code here
+ end
+ end
+ """
+ And a file named "spec/another_sample_spec.rb" with:
+ """
+ describe "something" do
+ it "does something" do
+ # put your code here
+ end
+ end
+ """
+ And a file named "spec/nested/a_nested_spec.rb" with:
+ """
+ describe "something" do
+ it "does something" do
+ # put your code here
+ end
+ end
+ """
+ When I run "stendhal spec/sample_spec.rb spec/nested/a_nested_spec.rb"
+ Then the exit status should be 0
+ And the output should contain "2 examples, 0 failures"
+
+ Scenario: running from rake
+ Given a directory named "stendhal_project"
+ And I cd to "stendhal_project"
+ And a directory named "spec"
+ And a directory named "spec/nested"
+ Given a file named "Rakefile" with:
+ """
+ require 'stendhal'
+ Stendhal::RakeTask.new
+ task :default => :spec
+ """
+ Given a file named "spec/sample_spec.rb" with:
+ """
+ describe "something" do
+ it "does something" do
+ # put your code here
+ end
+ end
+ """
+ And a file named "spec/another_sample_spec.rb" with:
+ """
+ describe "something" do
+ it "does something" do
+ # put your code here
+ end
+ end
+ """
+ And a file named "spec/nested/a_nested_spec.rb" with:
+ """
+ describe "something" do
+ it "does something" do
+ # put your code here
+ end
+ end
+ """
+ When I run "rake"
+ # Then the exit status should be 0
+ Then the output should contain "3 examples, 0 failures"
1  lib/stendhal.rb
View
@@ -1,3 +1,4 @@
+require 'stendhal/rake_task'
require 'stendhal/reporter'
require 'stendhal/exceptions'
require 'stendhal/matchers'
10 lib/stendhal/autorun.rb
View
@@ -1,7 +1,13 @@
-ARGV.each do |file|
- require File.join('.',file)
+unless ARGV.empty?
+ ARGV.each do |file|
+ require File.join('.',file)
+ end
+else
+ Dir['spec/**/*_spec.rb'].entries.each do |entry|
+ require File.join('.', entry)
+ end
end
examples, failures, pending = Stendhal::ExampleGroup.run_all
107 lib/stendhal/rake_task.rb
View
@@ -0,0 +1,107 @@
+#!/usr/bin/env ruby
+
+require 'stendhal'
+require 'rake'
+require 'rake/tasklib'
+
+module Stendhal
+ # Mostly taken from rspec-core Rake task
+ class RakeTask < ::Rake::TaskLib
+
+ # Name of task.
+ #
+ # default:
+ # :spec
+ attr_accessor :name
+
+ # By default, if there is a Gemfile, the generated command will include
+ # 'bundle exec'. Set this to true to ignore the presence of a Gemfile, and
+ # not add 'bundle exec' to the command.
+ #
+ # default:
+ # false
+ attr_accessor :skip_bundler
+
+ # Name of Gemfile to use
+ #
+ # default:
+ # Gemfile
+ attr_accessor :gemfile
+
+ # Whether or not to fail Rake when an error occurs (typically when examples fail).
+ #
+ # default:
+ # true
+ attr_accessor :fail_on_error
+
+ # A message to print to stderr when there are failures.
+ attr_accessor :failure_message
+
+ # Use verbose output. If this is set to true, the task will print the
+ # executed spec command to stdout.
+ #
+ # default:
+ # true
+ attr_accessor :verbose
+
+ # Command line options to pass to ruby.
+ #
+ # default:
+ # nil
+ attr_accessor :ruby_opts
+
+ # Path to stendhal
+ #
+ # default:
+ # 'stendhal'
+ attr_accessor :stendhal_path
+
+ def initialize(*args)
+ @name = args.shift || :spec
+ @ruby_opts = nil
+ @skip_bundler = false
+ @verbose, @fail_on_error = true, true
+ @gemfile = 'Gemfile'
+
+ yield self if block_given?
+
+ @stendhal_path ||= 'stendhal'
+
+ desc("Run Stendhal code examples") unless ::Rake.application.last_comment
+
+ task name do
+ RakeFileUtils.send(:verbose, verbose) do
+ begin
+ ruby(stendhal_command)
+ rescue
+ puts failure_message if failure_message
+ raise("ruby #{stendhal_command} failed") if fail_on_error
+ end
+ end
+ end
+ end
+
+ private
+
+ def stendhal_command
+ @stendhal_command ||= begin
+ cmd_parts = [ruby_opts]
+ cmd_parts << "-S"
+ cmd_parts << "bundle exec" if gemfile? unless skip_bundler
+ cmd_parts << stendhal_path
+ cmd_parts.flatten.compact.reject(&blank).join(" ")
+ end
+ end
+
+ private
+
+ def blank
+ lambda {|s| s == ""}
+ end
+
+ def gemfile?
+ File.exist?(gemfile)
+ end
+
+ end
+end
2  lib/stendhal/version.rb
View
@@ -1,3 +1,3 @@
module Stendhal
- VERSION = "0.1.7"
+ VERSION = "0.1.8"
end
Please sign in to comment.
Something went wrong with that request. Please try again.