我對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