[rspec-users] First encounter with RSpec, please help

David Chelimsky dchelimsky at gmail.com
Sun Aug 10 18:24:29 EDT 2008


On Sun, Aug 10, 2008 at 11:03 AM, Jesse Crockett <lists at ruby-forum.com> wrote:
> Hello, I'm working on a feature of insoshi to limit daily connection
> requests, using a boolean and integer value set by the admin.  The
> feature works fine, but causes 11 failures in `rake spec', not to
> mention the two or three tests for the new variables yet to be written.
>
> Here is the existing connection_spec, followed by
> connections_controller_spec
>
> ##
>
> require File.dirname(__FILE__) + '/../spec_helper'
>
> describe Connection do
>
>  before(:each) do
>    @emails = ActionMailer::Base.deliveries
>    @emails.clear
>    @global_prefs = Preference.find(:first)
>
>    @person = people(:quentin)
>    @contact = people(:aaron)
>  end
>
>  describe "class methods" do
>
>    it "should create a request" do
>      Connection.request(@person, @contact)
>      status(@person, @contact).should == Connection::PENDING
>      status(@contact, @person).should == Connection::REQUESTED
>    end
>
> #  abridged
>
> ###
> connections_controller_spec
>
> require File.dirname(__FILE__) + '/../spec_helper'
>
> describe ConnectionsController do
>  integrate_views
>
>  before(:each) do
>    @person  = login_as(:quentin)
>    @contact = people(:aaron)
>  end
>
>  it "should protect the create page" do
>    logout
>    post :create
>    response.should redirect_to(login_url)
>  end
>
>  it "should create a new connection request" do
>    Connection.should_receive(:request).with(@person, @contact).
>      and_return(true)
>    post :create, :person_id => @contact
>    response.should redirect_to(home_url)
>  end
>
> # abridged
>
> The two vars needed can be accessed in the connection_spec with
> @global_prefs.limit_requests and @global_prefs.daily_request_limit
>
> Please help me clear this problem.

Please post the code for Connection and Controller as well.

>
> The errors from `rake spec' --
>
> 1)
> Spec::Mocks::MockExpectationError in 'ConnectionsController should
> create a new connection request'
> Mock 'Class' expected :request with (I'm Quentin, I'm Aaron) once, but
> received it 0 times
> ./spec/controllers/connections_controller_spec.rb:18:
>
> 2)
> 'SearchesController Forum post searches should render with a topic link'
> FAILED
> Expected at least 1 element matching
> "a[href='/forums/953125641/topics/953125641#post_119261968']", found 0.
> <false> is not true.
> ./spec/controllers/searches_controller_spec.rb:174:
>
> 3)
> 'SearchesController Forum post searches should render with a post div'
> FAILED
> Expected at least 1 element matching "div[class='forum']", found 0.
> <false> is not true.
> ./spec/controllers/searches_controller_spec.rb:167:
>
> 4)
> 'SearchesController Forum post searches should search by topic name'
> FAILED
> Expected array to include #<ForumPost:0xb74944c4>
> ./spec/controllers/searches_controller_spec.rb:162:
>
> 5)
> 'SearchesController Forum post searches should search by post body'
> FAILED
> Expected array to include #<ForumPost:0xb6670e74>
> ./spec/controllers/searches_controller_spec.rb:148:
>
> 6)
> 'SearchesController Message searches should search by content' FAILED
> Expected array to include #<Message:0xb65cf240>
> ./spec/controllers/searches_controller_spec.rb:123:
>
> 7)
> 'SearchesController Message searches should search by subject' FAILED
> Expected array to include #<Message:0xb65a6f84>
> ./spec/controllers/searches_controller_spec.rb:118:
>
> 8)
> 'SearchesController Person searches as an admin should return email
> unverified users' FAILED
> Expected array to include #<Person:0xb653918c>
> ./spec/controllers/searches_controller_spec.rb:104:
>
> 9)
> 'SearchesController Person searches as an admin should return
> deactivated users' FAILED
> Expected array to include #<Person:0xb652f0d8>
> ./spec/controllers/searches_controller_spec.rb:96:
>
> 10)
> 'SearchesController Person searches should search by description' FAILED
> expected: [#<Person id: 745185059, email: "quentin at example.com", name:
> "Quentin", remember_token: nil, crypted_password:
> "tiM81jP/bSzxdKEpRXyd0osc/N9hXVDPQutJ7ZxsJCyKoXIRuBa...", description:
> "I'm Quentin", remember_token_expires_at: nil, last_contacted_at: nil,
> last_logged_in_at: "2008-08-10 10:19:06", forum_posts_count: 0,
> blog_post_comments_count: 0, wall_comments_count: 0, created_at:
> "2008-08-05 10:19:00", updated_at: "2008-08-10 10:19:06", admin: false,
> deactivated: false, connection_notifications: true,
> message_notifications: true, wall_comment_notifications: true,
> blog_comment_notifications: true, email_verified: true>],
>     got: [] (using ==)
> ./spec/controllers/searches_controller_spec.rb:64:
>
> 11)
> 'SearchesController Person searches should search by name' FAILED
> expected: [#<Person id: 745185059, email: "quentin at example.com", name:
> "Quentin", remember_token: nil, crypted_password:
> "tiM81jP/bSzxdKEpRXyd0osc/N9hXVDPQutJ7ZxsJCyKoXIRuBa...", description:
> "I'm Quentin", remember_token_expires_at: nil, last_contacted_at: nil,
> last_logged_in_at: "2008-08-10 10:19:06", forum_posts_count: 0,
> blog_post_comments_count: 0, wall_comments_count: 0, created_at:
> "2008-08-05 10:19:00", updated_at: "2008-08-10 10:19:06", admin: false,
> deactivated: false, connection_notifications: true,
> message_notifications: true, wall_comment_notifications: true,
> blog_comment_notifications: true, email_verified: true>],
>     got: [] (using ==)
> ./spec/controllers/searches_controller_spec.rb:59:
>
> Finished in 11.488971 seconds
>
> 366 examples, 11 failures


More information about the rspec-users mailing list