Skip to content

Commit

Permalink
refactor and tidy stepdefs
Browse files Browse the repository at this point in the history
- move modules to features/support
- reorganize modules for greater consistency
- reorganize steps in GWT order
- put similar steps together, so its easier to spot inconsistencies

features passing
  • Loading branch information
diabolo committed Mar 17, 2014
1 parent 5852023 commit c7f053a
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 80 deletions.
20 changes: 7 additions & 13 deletions features/step_definitions/custom_location_steps.rb
@@ -1,23 +1,17 @@
module LocationSH
def no_op; end

def custom_location
default_location+'.custom'
end

end
World LocationSH

Given(/^I have a custom location$/) do
Given /^I have a custom location$/ do
# hooks.rb setups a custom location, so we don't have to do anything here
no_op
end

When(/^I add a task with a custom location$/) do
When /^I add a task with a custom location$/ do
add_task location: custom_location
end

Then(/^my task should be stored in the custom location$/) do
Then "my task should be stored in the default location" do
task_present
end

Then /^my task should be stored in the custom location$/ do
task_present(location: custom_location)
end

73 changes: 6 additions & 67 deletions features/step_definitions/task_steps.rb
@@ -1,60 +1,7 @@
module TaskSH
def add_task(attrs={})
command = "#{xec(attrs)} new 'New todo item'"
runc command
end

def list_tasks(attrs={})
command = "#{xec(attrs)} list"
runc command
end

def task_count
`todo list | wc -l`.chomp.to_i
end

def default_location
Todo.location
end

def task_present(attrs={})
loc = attrs[:location] || default_location
count = attrs[:count] || 1

File.exist?(loc).should be_true
File.open(loc) do |f|
f.each_line.count.should == count
end
end

def some; 3; end

def should_see_some_tasks
@output.each_line.count.should == some
end
end
World TaskSH

module CommandSH
def runc(command)
@output = `#{command}`
end

def xec(attrs)
"#{executable}#{global_options(attrs)}"
end

def executable
# must end with a space
"todo "
end

def global_options(attrs)
# must end with a space
"-f #{attrs[:location]} " if attrs[:location]
end
Given /^I have added some tasks$/ do
some.times { add_task }
end
World CommandSH

When /^I add a task$/ do
add_task
Expand All @@ -64,24 +11,16 @@ def global_options(attrs)
n.to_i.times { add_task }
end

Then /^there should be (\d+) tasks$/ do |n|
task_count.should == n.to_i
When /^I list the tasks$/ do
list_tasks
end

Then /^there should be a task$/ do
task_count.should > 0
end

Then "my task should be stored in the default location" do
task_present
end

Given /^I have added some tasks$/ do
some.times { add_task }
end

When /^I list the tasks$/ do
list_tasks
Then /^there should be (\d+) tasks$/ do |n|
task_count.should == n.to_i
end

Then /^I should see some tasks$/ do
Expand Down
20 changes: 20 additions & 0 deletions features/support/command_sh.rb
@@ -0,0 +1,20 @@
module CommandSH
def runc(command)
@output = `#{command}`
end

def xec(attrs)
"#{executable}#{global_options(attrs)}"
end

def executable
# must end with a space
"todo "
end

def global_options(attrs)
# must end with a space
"-f #{attrs[:location]} " if attrs[:location]
end
end
World CommandSH
13 changes: 13 additions & 0 deletions features/support/location_sh.rb
@@ -0,0 +1,13 @@
module LocationSH
def default_location
Todo.location
end

def custom_location
"#{default_location}.custom"
end

end
World LocationSH


9 changes: 9 additions & 0 deletions features/support/misc_sh.rb
@@ -0,0 +1,9 @@
module MiscSH

def no_op; end

def some; 3; end

end
World MiscSH

31 changes: 31 additions & 0 deletions features/support/task_sh.rb
@@ -0,0 +1,31 @@
module TaskSH
def add_task(attrs={})
command = "#{xec(attrs)} new 'New todo item'"
runc command
end

def list_tasks(attrs={})
command = "#{xec(attrs)} list"
runc command
end

def task_count
`todo list | wc -l`.chomp.to_i
end

def task_present(attrs={})
loc = attrs[:location] || default_location
count = attrs[:count] || 1

File.exist?(loc).should be_true
File.open(loc) do |f|
f.each_line.count.should == count
end
end

def should_see_some_tasks
@output.each_line.count.should == some
end
end
World TaskSH

0 comments on commit c7f053a

Please sign in to comment.