开发者

Help with a Given step that goes to a page and as a logged in user

开发者 https://www.devze.com 2023-03-10 14:06 出处:网络
My scenerio looks like: Given I am on the homepage As a member When I follow \"new post\" .. .. In my web_steps.rb I added:

My scenerio looks like:

Given I am on the homepage
As a member
When I follow "new post"
..
..

In my web_steps.rb I added:

When /^As a (.+)$/ do |type|
  @user = Factory(:user, type)
end

My factories are in:

/spec/factories.rb
/spec/factories/user.rb

How do I reference my factories.rb into my web_steps.rb page? Am I doing this correctly? Now this instance variable @user is the variable that my controller checks to see if it is authenticated correct?

I'm getting this e开发者_C百科rror currently:

features/create_post.feature: Lexing error on line 8: ' As a member'.

What is wrong with my 'As a member' line?

Update

I noticed I had:

When /^As a

I changed it to:

As /^a

now I get:

undefined method `As' for main:Object (NoMethodError)


'As' is not valid in a cucumber scenario as far as I know.

Your lines should start with 'Given', 'When', 'Then', or 'And'.

Your scenario should probably look more like

Given I am logged in as 'User'
When I go to the homepage
And I follow "New post"
Then ...


Rather than write web steps that instantiate factories, i use Pickle for this. Pickle is nice, because you don't have to futz with your factories at all in cucumber. It defines generic steps for creating any given factory object (model), as well as steps for finding model objects and other things.

Ryan Bates has a created a screenscast on pickle as well. Rails screencasts are a nice post-lunch office tradition around our place!

Ok, good luck,

ian.

0

精彩评论

暂无评论...
验证码 换一张
取 消