I am very new to cucumber and rspec, but do have some rails and ruby understanding.
The gems in question are: Devise, Declarative_Authorization, and role_model
Rails 3 is what I am using and ruby 1.9.2-rc2
remember I do NOT know what I am doing
I have written a Feature:
Feature: As the administrator of the site give me quick access to information
In order to do lots of stuff
As an administrator
I want to see reports and stuff
Background:
Given a logged in user with a role of "admin"
Scenario: Admin can see links
Given I am on the admin dashboard page
Then I should see all admin links
With some web steps:
module AdminDashboardHelpers
def current_user_session
return @user_session if defined?(@user_session)
@user_session = user_session
end
def current_user
return @current_user if defined?(@current_user)
@current_user = current_user_session && current_user_session.user
end
def admin_signed_in?
@user = current_user
@user.has_role?(:admin)
end
end
World(AdminDashboardHelpers)
Given /^a logged in user with a role of "([^\"]*)"$/ do |role|
visit new_user_session_path
fill_in "Login", :with => "iam"
fill_in "Password", :with => "secret"
click_button "Log in"
admin_signed_in?
#@current_user.should has_role?(role)
end
Then /^I should see all admin links$/ do
pending # express the regexp above with the code you wish you had
end
My problem is that when I run the feature I receive an error saying undefined local variable or method `user_session' for #Cucumber::Rails::World:0x8077e1f8
I was under the assumption that user_session was a method that came with devise. How do I test if a user is a certain role?
Or better yet how do I tell cucumber about the methods that are in the rails app provided by gems? Thank you for your time, it is greatly appreciated. --iAm