story based Integration test

Hi all, I’ve been working with Beginning Rails 3 book, I’m in the Test Chapter, and I’m trying to extend the story based integration test.

I’ve the following:

class UserStoriesTest < ActionDispatch::IntegrationTest

fixtures :all

test “should emulate articles life-cicle” do

admin = registered_user

guest = registered_user

admin.logs_in “sphi02ac@gmail.com”, “secret”

guest.logs_in “guest@mail.com”, “secret”

admin.creates_article :title => “Admin creates an article”, :body => “Lorem ipsum dolor sit amet…”

guest.creates_article :title => “Guest creates an article”, :body => “Lorem ipsum dolor sit amet…”

admin.comment_article(Article.find_by_title(“Admin creates an article”))

guest.comment_article(Article.find_by_title(“Guest creates an article”))

admin.logs_out

guest.logs_out

end

private

def registered_user

open_session do |user|

def user.logs_in(email, password)

get login_path

assert_response :success

assert_template ‘new’

post session_path, :email => email, :password => password

assert_response :redirect

assert_redirected_to root_path

follow_redirect!

assert_response :success

assert_template :index

assert session[:user_id]

end

def user.logs_out

get logout_path

assert_response :redirect

assert_redirected_to root_path

assert_nil session[:user]

follow_redirect!

assert_template ‘index’

end

def user.creates_article(article_hash)

get new_article_path

assert_response :success

assert_template ‘new’

post articles_path, :article => article_hash

assert assigns(:article).valid?

assert_response :redirect

assert_redirected_to article_path(assigns(:article))

follow_redirect!

assert_response :success

assert_template ‘show’

end

end

end

end

So, I want to create another method with the following signature

def user.comment_article(article)
get new_article_comment_path(article)

assert_response :success
assert_template ‘create’

post article_comment_path, :comment => {
:name => “Guest”,
:email => “guest@mail.com”,
:body => “Lorem ipsum dolor sit amet…” }

assert assigns(:comment).valid?
end

But, it doesn’t work. Can you tell me guys, how to create that method to test when the user comment an related article.

Regards,

Amador Antonio Cuenca wrote in post #969855:

Hi all, I've been working with *Beginning Rails 3 book, *I'm in the Test
Chapter, and I'm trying to extend the story based integration test.

The best tool for story-based tests is Cucumber. I highly recommend
using it instead of Test::Unit's story framework.

Best,