On Fri, Jul 22, 2011 at 1:50 PM, internetchris <ch...@utilitygo.net> wrote:

> Hi Group,
>
> I'm finally taking the time to implement tests in some of my old apps.
> I'm using Rails 2.3.5, Rspec 1.3.1, Rspec-rails 1.3.3, and capybara.
>
> Here's an example of my first test, but I'm wondering how I setup the
> login routine so I can use it in future specs without repeating the
> method. Some sort of  -  before.each (:login)
>
> Can someone explain best practices for integration tests and if you're
> generous a simple code example.
>
>
> require 'spec_helper'
>
> describe "Users" do
>  before(:each) do
>    @user = Factory(:user)
>  end
>
>  it "login" do
>    visit login_path
>    fill_in :login, :with => @user.email
>    fill_in :password, :with => @user.password
>    click_button "login_button"
>    page.has_content?("Logged in successfully")
>  end
>
>  it "creat profile" do
>     visit new_social_profile_path
>  end
>
> end
> _______________________________________________
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>


Just put all of it in a method:

def login(user)
   visit login_path
   fill_in :login, :with => user.email
   fill_in :password, :with => user.password
   click_button "login_button"
end

before(:each) { login }

You can put the method in spec/support (and require it in spec_helper), or,
define it in spec_helper
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to