[rspec-users] Default format for all requests in a spec

Justin Ko jko170 at gmail.com
Fri Aug 27 03:00:24 EDT 2010


Well, you could setup a default parameter hash:

describe MyController do
  let(:params) { {:format => 'js'} }

  describe '#show' do
    it '...' do
      get :show, params.merge(:id => 1)
    end
  end
end

You could also take it another level:

describe MyController do
  let(:params) { {:format => 'js'} }

  describe '#show' do
    before { params.merge(:id => 1) }

    it '...' do
      get :show, params.merge(:another_param => 'yep')
    end
  end
end

On Aug 26, 9:12 am, Maurício Linhares <mauricio.linha... at gmail.com>
wrote:
> Hi guys,
>
> Is there a way to define a default parameter for all requests made in a spec?
>
> I have a spec where I want all requests to be made with the "js"
> format but I find it rather annoying to type a ":format => 'js'" on
> every get/post/put/delete. Is there any other way to do this?
>
> -
> Maurício Linhareshttp://codeshooter.wordpress.com/|http://twitter.com/mauriciojr
> _______________________________________________
> rspec-users mailing list
> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users


More information about the rspec-users mailing list