[rspec-users] Eliminating duplication from tests

Brandon Olivares programmer2188 at gmail.com
Fri Apr 10 03:38:06 EDT 2009

> -----Original Message-----
> From: rspec-users-bounces at rubyforge.org [mailto:rspec-users-
> bounces at rubyforge.org] On Behalf Of David Chelimsky
> Sent: Friday, April 10, 2009 3:10 AM
> To: rspec-users
> Subject: Re: [rspec-users] Eliminating duplication from tests
> Can you please post specific examples of the use of these so we don't
> have to talk in generalities?

Sure, here is something I just wrote.

    def assert_route_recognition path, controller, methods
      describe "route recognition" do
        [:get, :post, :put, :delete].each do |method|
          if methods.include? method
            it "should generate the params" +
            " {:controller => '#{controller}', :action =>
'#{methods[method]}'}" +
            " when the request method is #{method.to_s.upcase}" do
              params_from(method, path).should == {
              :controller => controller,
              :action => methods[method]
            it "should not accept the #{method} method" do
              lambda {
                params_from(method, path)
              }.should raise_error(ActionController::MethodNotAllowed)
    end # assert_route_recognition
> Of course your "testing" is progressing towards something more
> "test-like." You're calling it "testing" so you're probably thinking
> of it as "testing." You're using words like "ensure" instead of
> "specify" and you've even named your expectations "assert_xxx" instead
> of "expect_xxx."

Interesting. I'm just used to thinking that way I guess. What is wrong with
ensure instead of specify?

And I've never seen that convention with the expect prefix. Can you provide
an example?

Thank you very much for the help.


More information about the rspec-users mailing list