Skip to content

Commit

Permalink
update libraries for modularity
Browse files Browse the repository at this point in the history
  • Loading branch information
joelparkerhenderson committed Mar 21, 2011
1 parent 19185aa commit 83136c5
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 30 deletions.
12 changes: 12 additions & 0 deletions step_definitions/given_my_role_is_x.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This step uses our Role Based Access Control (RBAC)
# which can have multiple roles, each identified by
# an "external id" (id) that is typically one word
# like "administrator", "manager", "assistant", etc.
#
# Example:
# Given my role is an Administrator
# => @user.rbac_roles=[Factory(:rbac_role, :xid => 'administrator")

Given /my role is (?:|an? )(\w+)/i do |rbac_role_xid|
@user.rbac_roles=[Factory(:rbac_role, :xid => rbac_role_xid.downcase)]
end
14 changes: 14 additions & 0 deletions step_definitions/given_there_are_n_models.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# A Cucumber step to generate any number of objects, for any model, typically using factory girl
# http://cassiomarques.wordpress.com/2009/04/16/a-cucumber-step-to-generate-any-number-of-objects-for-any-model/
Given /^there are (\d+) (.+)$/ do |n, model_str|
model_str = model_str.gsub(/\s/, '_').singularize
model_sym = model_str.to_sym
klass = eval(model_str.camelize)
klass.transaction do
klass.destroy_all
n.to_i.times do |i|
Factory(model_sym)
end
end
end

7 changes: 7 additions & 0 deletions step_definitions/i_am_a_user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Given /I am a user/ do
@user= Factory(:user)
end

def current_user
@user
end
30 changes: 0 additions & 30 deletions step_definitions/user_steps.rb → step_definitions/misc_steps.rb
Original file line number Diff line number Diff line change
@@ -1,36 +1,6 @@
require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))


###############################################################
#
# Users
#
###############################################################

Given /I am a user/ do
@user= Factory(:user)
end

def current_user
@user
end

###############################################################
#
# Roles
#
###############################################################

Given /my role is (\w+)/i do |rbac_role_xid|
@user.rbac_roles=[Factory(:rbac_role, :xid => rbacrole_xid)]
end

Given /I am an admin/ do
Given "I am a user"
Given "my role is admin"
end


###############################################################
#
# Sign In
Expand Down
5 changes: 5 additions & 0 deletions step_definitions/then_i_should_see_button_x_within_y.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Then /^(?:|I )should see button "([^"]*)"(?: within "([^"]*)")?$/ do |button_name, selector|
with_scope(selector) do
find_button(button_name)!=nil
end
end
32 changes: 32 additions & 0 deletions step_definitions/then_i_should_see_my_x.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/env ruby
#
# Cucumber step to say "Then I should see my ..."
#
# The "my" is the user returned by the #current_user method.
#
# The "..." can be any user method name written in plain English.
# The method name is converted to a method symbol in three steps:
# - delete periods
# - change non-alphanumerics to underscores
# - downcase
#
# The leading "I" and trailing "." are optional as usual.
#
# Examples:
# Then I should see my name
# => Then I should see current_user.name
#
# should see my U.S. postal address.
# => Then I should see current_user.us_postal_address

Then /^(?:|I )should see my (.+)\.?$/ do |target|
case target
user = @user || current_user
method_sym = target.gsub(/\./,'').gsub(/\W+/,'_').downcase.to_sym
if user.methods.include?(method_sym)
target_text = current_user.send(method_sym)
Then "I should see \"#{target_text}\""
default
raise "The current user does not have a target \"#{target}\" method \"#{method_sym}\""
end
end
10 changes: 10 additions & 0 deletions support/factory_girl.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Cucumber support for Factory Girl by ThoughtBot
require "factory_girl"

# Require Factory Girl's included step definitions;
# these enable creating many factories easily.
require "factory_girl/step_definitions"

# Require our factories, which we put in the /factories directory
Dir.glob(File.join(Rails.root, 'factories', '*.rb')).each {|f| require f }

0 comments on commit 83136c5

Please sign in to comment.