我对cucumber和rspec很新,但是有一些rails和ruby的理解。Cucumber Help in Rails 3
有问题的宝石有:设计,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的::全球 未定义的局部变量或方法`USER_SESSION”:0x8077e1f8
我的假设下该user_session是一个设计来的方法。 如何测试用户是否具有某种特定角色?
或者更好的是,我该如何告诉黄瓜有关由宝石提供的rails应用程序的方法? 谢谢你的时间,这是不胜感激。 --iAm
谢谢你的回答,我会改变我的方法并继续阅读这个主题。 – creativeKoder 2010-08-18 14:40:11
我的另一个问题是,如果我想要忠于BDD,我应该从一个黄瓜还是rspec测试开始? – creativeKoder 2010-08-18 16:05:07
我推荐阅读Prag Press的Rspec书(http://pragprog.com/titles/achbd/the-rspec-book),但通常你先写功能,编写步骤,使用红色构建视图逻辑:绿色:在Rspec中重构,然后是rspec中的控制器逻辑,然后是对象,然后返回到黄瓜,并希望看到一步传递.. – Doon 2010-08-18 16:23:46