Created
August 23, 2011 21:06
-
-
Save faraazkhan/1166540 to your computer and use it in GitHub Desktop.
Cucumber Step Definition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# step helpers | |
def create_user(options) | |
@users ||= {} | |
role_name = options.delete :role_name | |
email = "#{role_name.downcase.gsub(' ','.')}@blackmanjones.com" | |
options[:email] = email | |
options.merge!(:username => email, :email => email, :password => 'password', :password_confirmation => 'password') | |
@users[role_name] ||= begin | |
user = User.make(options) | |
user.roles = [Role[role_name]] | |
user | |
end | |
end | |
# Given steps | |
Given /^I have a.? "([^"]*)" account$/ do |role_name| | |
create_user(:role_name => role_name) | |
end | |
Given /^there is a "([^"]*)" with the name "([^"]*)"$/ do |role_name, full_name| | |
full_name = full_name.split(' ') | |
create_user(:role_name => role_name, :first_name => full_name[0], :last_name => full_name[1]) | |
end | |
Given /^I have a.? "([^"]*)" with a.? "([^"]*)" task$/ do |workitem_name, task_type| | |
current_user = User.first | |
workitem = case workitem_name | |
when 'complaint document' | |
Document.make(:document_type => DocumentType['Complaint']) | |
end | |
current_user.tasks.make(:task_type => TaskType[task_type], :workitem => workitem) | |
end | |
Given /^there is a student with the name "([^"]*)"$/ do |full_name| | |
full_name = full_name.split(' ') | |
Student.make(:first_name => full_name[0], :last_name => full_name[1]) | |
end | |
Then /debug/ do | |
require 'ruby-debug/debugger' | |
"" | |
end | |
# And steps | |
And /^I wait for the AJAX calls to finish$/ do | |
loop do | |
sleep 1 | |
begin | |
count = page.evaluate_script('window.ajaxCalls').to_i | |
break if count.zero? | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment