【发布时间】:2010-08-17 14:41:34
【问题描述】:
我对 cucumber 和 rspec 很陌生,但对 rails 和 ruby 有一些了解。
有问题的宝石是:Devise、Declarative_Authorization 和 role_model
我正在使用 Rails 3 和 ruby 1.9.2-rc2
记住我不知道我在做什么
我写了一个功能:
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
通过一些网络步骤:
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
我的问题是,当我运行该功能时,我收到一条错误消息 #Cucumber::Rails::World:0x8077e1f8 的未定义局部变量或方法 `user_session'
我假设 user_session 是设计附带的一种方法。 如何测试用户是否是某个角色?
或者更好的是,我如何告诉 cucumber gems 提供的 rails 应用程序中的方法? 感谢您的宝贵时间,非常感谢。 --iAm
【问题讨论】:
标签: rspec ruby-on-rails-3 cucumber integration-testing