volontariat/voluntary_text_creation

View on GitHub
dummy/features/step_definitions/task_steps.rb

Summary

Maintainability
A
20 mins
Test Coverage
module TaskFactoryMethods
  def new_task(name, options = {})
    factory = options[:factory] || :task
    attributes = options[:attributes] || {}
    
    attributes.merge!({name: name})
    set_task_defaults(attributes)
    @task = FactoryGirl.create(factory, attributes)
    @task.reload
    
    @task
  end
    
  def set_task_defaults(attributes)
    attributes[:story_id] ||= @story.id if @story && !attributes[:story_id]
  end
end

World(TaskFactoryMethods)

Given /^a task named "([^\"]*)"$/ do |name|
  new_task(name)
end

Then /^I should see the following tasks:$/ do |expected_table|
  rows = find('table').all('tr')
  table = rows.map { |r| r.all('th,td').map { |c| c.text.strip } }
  expected_table.diff!(table)
end