Skip to content

Commit

Permalink
Conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Josep M. Bach committed Nov 13, 2010
2 parents adf3f95 + 488d134 commit dfd8c72
Show file tree
Hide file tree
Showing 5 changed files with 195 additions and 1 deletion.
14 changes: 14 additions & 0 deletions Readme.md
Expand Up @@ -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()
Expand All @@ -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
Expand Down
72 changes: 72 additions & 0 deletions features/cli.feature
Expand Up @@ -35,3 +35,75 @@ Feature: Command line interpreter
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 change: 1 addition & 0 deletions lib/stendhal.rb
@@ -1,3 +1,4 @@
require 'stendhal/rake_task'
require 'stendhal/reporter'
require 'stendhal/exceptions'
require 'stendhal/matchers'
Expand Down
107 changes: 107 additions & 0 deletions lib/stendhal/rake_task.rb
@@ -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 changes: 1 addition & 1 deletion lib/stendhal/version.rb
@@ -1,3 +1,3 @@
module Stendhal
VERSION = "0.1.7"
VERSION = "0.1.8"
end

0 comments on commit dfd8c72

Please sign in to comment.