On Sat, Aug 15, 2009 at 5:35 AM, Chamnap<[email protected]> wrote:
> I tried several hours to mock. What I want is basically to send "http
> accept" let's say "application/json" and want rails to send data back
> in json. Therefore, i need to mock that headers to do a test. I think
> I mocked that header already, but rails still sends me back in xml.
> Anyone could help me?

I think you mean stub (mocking means setting an expectation that a
message is received - sounds like you're just trying to set a value
for the controller to access).

Assuming you're using a rails version using rack (can't remember when
that was introduced - 2.1?), you can do this:

it "should return json" do
  request.env['ACCEPT'] = "application/json"
  get whatever_the_path_is
  ...
end

HTH,
David
_______________________________________________
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to