Skip to content

Instantly share code, notes, and snippets.

@rogerleite
Created May 13, 2010 17:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rogerleite/400069 to your computer and use it in GitHub Desktop.
Save rogerleite/400069 to your computer and use it in GitHub Desktop.
Sample sources for post: http://wp.me/piFiH-an
begin
require 'cucumber/rake/task'
Cucumber::Rake::Task.new(:cucumber) do |t|
t.cucumber_opts = "features --format pretty"
end
namespace :cucumber do
Cucumber::Rake::Task.new(:wip) do |t|
t.cucumber_opts = "features --format pretty -t @wip --wip"
end
end
rescue LoadError
desc 'cucumber rake task not available (cucumber not installed)'
task :cucumber do
abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem.'
end
end
require "fileutils"
OUTPUT = 'tmp/output.log'
SHOW_OUTPUT = !!ENV["show_output"]
#rake cucumber show_output=true #to show output
Before do
FileUtils.rm_f OUTPUT
FileUtils.mkdir_p File.dirname(OUTPUT)
end
#execute system command, redirecting output
def execute(command)
#2>&1 Redirect standard error to standard output
system("#{command} > #{OUTPUT} 2>&1")
puts File.read(OUTPUT) if SHOW_OUTPUT
end
#read output
def output
File.read(OUTPUT)
end
#Change some commands if necessary
def gsub_command(system_command)
command = system_command
if system_command =~ /^gem/
command << " --config-file=features/resources/gem-cucumber.yml"
end
command
end
When /^I run "([^\"]*)"$/ do |syscommand|
command = gsub_command(syscommand)
execute(command)
end
Then /^I should see "([^\"]*)"$/ do |data|
output.should match(Regexp.new(Regexp.escape(data)))
end
Then /^I should not see "([^\"]*)"$/ do |data|
output.should_not match(Regexp.new(Regexp.escape(data)))
end
Then /^I should see file "([^\"]*)" content like$/ do |filename, content|
File.read(filename).should == content
end
Given /^I have a file "([^\"]*)" with content$/ do |filename, content|
File.open(filename, "w+") { |file| file.puts content }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment