[rspec-users] cucumber is_admin? testing

Alex Whiteland lists at ruby-forum.com
Mon Nov 28 23:07:44 EST 2011

> 1. actually log in (i.e. create a user, go to the login screen and log
> in). You can wrap this in a single step definition like "Given I am
> logged in as 'admin'", but you still have to go through the app within
> the step definition.
I do this. Here is example:

Scenario: guest becomes a user
  Given I am guest
  When I go to the signup_path
  And puts signup info
  Then new user should be created
  And I should signin

> Smth.

Given /^I am guest$/ do
  get_me_the_cookies.should eq([])

When /^I go to the signup_path$/ do
  visit signup_path

When /^puts signup info$/ do
  fill_in "user_username", :with => "frankpopp"
  fill_in "user_first", :with => "Frank"
  fill_in "user_second", :with => "Popp"
  fill_in "user_password", :with => "123456"
  fill_in "user_password_confirmation", :with => "123456"
  click_button "Sign up!"

Then /^new user should be created$/ do
  page.should have_content("New user added: frankpopp")

Then /^I should signin$/ do
  is_user?.should be_true

> in users_controller.rb:
  def create
   @user = User.new(params[:user])
   if @user.save
    session[:user_id] = @user.id # This create a session
    flash[:success] = "New user added: " + @user.username
    flash[:notice] = "His password is: " + @user.password if is_admin?
    redirect_to @user


Posted via http://www.ruby-forum.com/.

More information about the rspec-users mailing list