Permalink
Browse files

cuke tools

  • Loading branch information...
1 parent 5cd41d3 commit 22e2a6449dba2fd6ebd7b1bd70b4922aca74739c @dchelimsky dchelimsky committed Feb 6, 2010
@@ -1,12 +1,16 @@
-Given %r{^a file named "([^"]+)" with:$} do |file_name, code|
+Given /^a directory named "([^"]+)"$/ do |dirname|
+ create_dir(dirname)
+end
+
+Given /^a file named "([^"]+)" with:$/ do |file_name, code|
create_file(file_name, code)
end
-When %r{^I run "r?spec ([^"]+)"$} do |file_and_args|
+When /^I run "r?spec ([^"]+)"$/ do |file_and_args|
spec(file_and_args)
end
-When %r{^I run "ruby ([^"]+)"$} do |file_and_args|
+When /^I run "ruby ([^"]+)"$/ do |file_and_args|
ruby(file_and_args)
end
@@ -26,6 +26,10 @@ def spec(args)
ruby("#{spec_command} #{args}")
end
+ def create_dir(dirname)
+ FileUtils.mkdir_p File.join(working_dir, dirname)
+ end
+
def create_file(file_name, contents)
file_path = File.join(working_dir, file_name)
File.open(file_path, "w") { |f| f << contents }
@@ -1,14 +1,33 @@
require 'rspec/expectations'
Rspec::Matchers.define :smart_match do |expected|
+ def regexp?
+ /^\/.*\/?$/
+ end
+
+ def quoted?
+ /^".*"$/
+ end
+
match do |actual|
case expected
- when /^\/.*\/?$/
+ when regexp?
actual =~ eval(expected)
- when /^".*"$/
+ when quoted?
actual.index(eval(expected))
- else
- false
+ else # multi-line string
+ actual.index(expected)
end
end
+
+ failure_message_for_should do |actual|
+ <<-MESSAGE
+#{'*'*50}
+got:
+#{'*'*30}
+#{actual}
+#{'*'*50}
+MESSAGE
+ end
+
end

0 comments on commit 22e2a64

Please sign in to comment.