Skip to content

Commit

Permalink
begin migrating stories to cucumber features
Browse files Browse the repository at this point in the history
  • Loading branch information
dchelimsky committed Dec 18, 2008
1 parent 07a299e commit a8ae31d
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 2 deletions.
7 changes: 6 additions & 1 deletion Rakefile
Expand Up @@ -5,6 +5,7 @@ require 'rubygems'
require 'hoe'
require 'spec/version'
require 'spec/rake/spectask'
require 'cucumber/rake/task'

class Hoe
def extra_deps
Expand All @@ -19,14 +20,15 @@ Hoe.new('rspec', Spec::VERSION::STRING) do |p|
p.description = "Behaviour Driven Development for Ruby."
p.rubyforge_name = 'rspec'
p.developer('RSpec Development Team', 'rspec-devel@rubyforge.org')
p.extra_deps = [["cucumber",">= 0.1.13"]]
p.remote_rdoc_dir = "rspec/#{Spec::VERSION::STRING}"
end

['audit','test','test_deps','default','post_blog'].each do |task|
Rake.application.instance_variable_get('@tasks').delete(task)
end

task :verify_rcov => [:spec, :stories]
task :verify_rcov => [:spec, :features, :stories]
task :default => :verify_rcov

# # Some of the tasks are in separate files since they are also part of the website documentation
Expand All @@ -46,6 +48,9 @@ Spec::Rake::SpecTask.new do |t|
end
end

desc "Run Cucumber features"
Cucumber::Rake::Task.new do; end

desc "Run all stories"
task :stories do
ruby "stories/all.rb --colour --format plain"
Expand Down
@@ -1,4 +1,4 @@
Story: autogenerated docstrings
Feature: autogenerated docstrings

As an RSpec user
I want examples to generate their own names
Expand Down
32 changes: 32 additions & 0 deletions features/step_definitions/running_rspec.rb
@@ -0,0 +1,32 @@
Given /^the file (.*)$/ do |relative_path|
@path = File.expand_path(File.join(File.dirname(__FILE__), "..", "resources", relative_path))
unless File.exist?(@path)
raise "could not find file at #{@path}"
end
end

When /^I run it with the (.*)$/ do |interpreter|
stderr_file = Tempfile.new('rspec')
stderr_file.close
@stdout = case(interpreter)
when /^ruby interpreter/
args = interpreter.gsub('ruby interpreter','')
ruby("#{@path}#{args}", stderr_file.path)
when /^spec script/
args = interpreter.gsub('spec script','')
spec("#{@path}#{args}", stderr_file.path)
when 'CommandLine object' then cmdline(@path, stderr_file.path)
else raise "Unknown interpreter: #{interpreter}"
end
@stderr = IO.read(stderr_file.path)
@exit_code = $?.to_i
end

Then /^the (.*) should match (.*)$/ do |stream, string_or_regex|
written = case(stream)
when 'stdout' then @stdout
when 'stderr' then @stderr
else raise "Unknown stream: #{stream}"
end
written.should smart_match(string_or_regex)
end
25 changes: 25 additions & 0 deletions features/support/env.rb
@@ -0,0 +1,25 @@
require 'tempfile'
require File.dirname(__FILE__) + '/../../spec/ruby_forker'
require File.dirname(__FILE__) + '/../../stories/resources/matchers/smart_match'

require 'spec/expectations'
require 'spec/matchers'

module RspecWorld
include Spec::Expectations
include Spec::Matchers
include RubyForker

def spec(args, stderr)
ruby("#{File.dirname(__FILE__) + '/../../bin/spec'} #{args}", stderr)
end

def cmdline(args, stderr)
ruby("#{File.dirname(__FILE__) + '/../../resources/helpers/cmdline.rb'} #{args}", stderr)
end
end

World do |world|
world.extend(RspecWorld)
world
end

0 comments on commit a8ae31d

Please sign in to comment.