how do I write a good rspec for this?

21 views
Skip to first unread message

roelof

unread,
Nov 12, 2012, 12:36:00 PM11/12/12
to rs...@googlegroups.com
Hello,

I have this step-definitions file:

Given /^a user "(.*?)" exists$/ do |user_name|
    @user = User.create!(:username => user_name , :password => "tamara")
end

When /^he logs in$/ do
  visit("/login")
  fill_in('Username', :with => "roelof")
  fill_in('Password', :with => "tamara")
   click_button("Login")
end

Then /^he should see "(.*?)"$/ do |message|
  page.should have_content(message)
end

When /^he logs in with a bad password$/ do
  visit("/login")
  fill_in('Username', :with => "roelof")
  fill_in('Password', :with => "roelof")
   click_button("Login")
end

Then /^he should not see "(.*?)"$/ do |message|
    page.should_not have_content(message)
end

eveything is green here.

But now I wonder how I can test this using Rspec and have a good rspec file.
Who can give me some tips ?

Roelof




Alex Chaffee

unread,
Nov 12, 2012, 8:40:06 PM11/12/12
to rs...@googlegroups.com, rs...@googlegroups.com
Why do you want to write an rspec test? Is there something your Cucumber test isn't covering?
--
You received this message because you are subscribed to the Google Groups "rspec" group.
To post to this group, send email to rs...@googlegroups.com.
To unsubscribe from this group, send email to rspec+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/rspec/-/QaZjSc2gjPAJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

roelof

unread,
Nov 13, 2012, 1:41:22 AM11/13/12
to rs...@googlegroups.com
Because I thought it is the normal way that BDD works. First write the Cucumber test and then write the rspec test.
There is nothing that the cucumber test is not covering. 
 
Roelof
 

Op dinsdag 13 november 2012 02:41:42 UTC+1 schreef Alex Chaffee het volgende:

Alex Chaffee

unread,
Nov 13, 2012, 12:00:02 PM11/13/12
to rs...@googlegroups.com, rs...@googlegroups.com


On Nov 12, 2012, at 10:41 PM, roelof <rwo...@hotmail.com> wrote:

> There is nothing that the cucumber test is not covering.

High five! You win :-)

Tests are a means to an end, not an end in themselves.

You may want to unit test the model(s) independently, but most of what you showed is testing app flow and web pages, using capybara, so doing the same thing in an rspec test would just be redundant.
Reply all
Reply to author
Forward
0 new messages