Skip to content
Browse files

New step definition for appending to a file

  • Loading branch information...
1 parent a147289 commit 2afd02b7d44102119f20179763c85340e919f71d @aslakhellesoy aslakhellesoy committed Feb 23, 2010
Showing with 28 additions and 2 deletions.
  1. +3 −0 History.txt
  2. +1 −1 Rakefile
  3. +14 −1 features/file_system_commands.feature
  4. +6 −0 lib/aruba/api.rb
  5. +4 −0 lib/aruba/cucumber.rb
View
3 History.txt
@@ -1,3 +1,6 @@
+== 0.1.4
+* New step definition for appending to a file (Aslak Hellesøy)
+
== 0.1.3
* New step definition for cd (change directory) (Aslak Hellesøy)
View
2 Rakefile
@@ -4,7 +4,7 @@ require 'rake'
begin
require 'jeweler'
Jeweler::Tasks.new do |gem|
- gem.version = "0.1.3"
+ gem.version = "0.1.4"
gem.name = "aruba"
gem.summary = %Q{CLI Steps for Cucumber}
gem.description = %Q{CLI Steps for Cucumber, hand-crafted for you in Aruba}
View
15 features/file_system_commands.feature
@@ -9,14 +9,27 @@ Feature: file system commands
When I run "ruby -e \"puts test ?d, 'foo'\""
Then the stdout should contain "true"
- Scenario: cat a file
+ Scenario: create a file
Given a file named "foo/bar/example.rb" with:
"""
puts "hello world"
"""
When I run "ruby foo/bar/example.rb"
Then I should see "hello world"
+ Scenario: append to a file
+ Given a file named "foo/bar/example.rb" with:
+ """
+ puts "hello world"
+ """
+ When I append to "foo/bar/example.rb" with:
+ """
+ puts "this was appended"
+ """
+ When I run "ruby foo/bar/example.rb"
+ Then I should see "hello world"
+ And I should see "this was appended"
+
Scenario: clean up files generated in previous scenario
When I run "ruby foo/bar/example.rb"
Then the exit status should be 1
View
6 lib/aruba/api.rb
@@ -27,6 +27,12 @@ def create_file(file_name, file_content)
end
end
+ def append_to_file(file_name, file_content)
+ in_current_dir do
+ File.open(file_name, 'a') { |f| f << file_content }
+ end
+ end
+
def create_dir(dir_name)
in_current_dir do
_mkdir(dir_name)
View
4 lib/aruba/cucumber.rb
@@ -14,6 +14,10 @@
create_file(file_name, file_content)
end
+When /^I append to "([^\"]*)" with:$/ do |file_name, file_content|
+ append_to_file(file_name, file_content)
+end
+
When /^I cd to "([^\"]*)"$/ do |dir|
cd(dir)
end

0 comments on commit 2afd02b

Please sign in to comment.
Something went wrong with that request. Please try again.