[Rspec-devel] New proc.should_increment method

David Chelimsky dchelimsky at gmail.com
Fri Jul 14 09:21:29 EDT 2006


On 7/13/06, aslak hellesoy <aslak.hellesoy at gmail.com> wrote:
> I just added a new little goodie:
>
> arr = []
> lambda { arr << "something" }.should_increment arr, :length
>
> See http://rubyforge.org/tracker/?func=detail&atid=3152&aid=5055&group_id=797
>
> A little bit on the state side of the fence (as opposed to
> behavioural), but it's still a nice little feature methinks.

-1

I saw in the page linked above "State based testing isn't ALWAYS bad".
I agree w/ that statement, but I also think that it's important that
rspec offers better solutions rather than conveniences.

In the case of the rails controller tests, I've been working on an
acts_as_mock plugin that allows you to mock the class methods as well
as instance methods, allowing for this (expressed in test/unit for the
time being - apologies):

  def test_create_should_redirect_to_list_when_successful
    Story.should_receive(:new).and_return(@story)
    @story.should_receive(:save).and_return(true)

    post :create

    assert_response :redirect
    assert_template nil
  end

  def test_create_should_re_render_new_when_NOT_successful
    Story.should_receive(:new).and_return(@story)
    @story.should_receive(:save).and_return(false)

    post :create

    assert_response :success
    assert_template 'new'
  end


To me, this is the direction we should be moving, rather than making
it convenient to do things that we want to generally discourage.

This also brings up an important, higher level discussion vis a vis
what features should be going into rspec. I'll get that rolling in a
separate thread.

David


More information about the Rspec-devel mailing list