-1

I am new to Rspec. How to write controller code to connect to localhost:3000/v.json link in Rspec and check the title is as expected?

JSON format is  {id: 1, title: "new"}

Please help!

Lukas Stejskal
  • 2,542
  • 19
  • 30
jos
  • 45
  • 5
  • Possible duplicate of [How to check for a JSON response using RSpec?](http://stackoverflow.com/questions/5159882/how-to-check-for-a-json-response-using-rspec) – Sinscary Jul 29 '16 at 11:34
  • How to connect to the link(URL)? – jos Jul 29 '16 at 11:38

1 Answers1

0

You need a functional test of your controller, that hits your action, with something like this:

@expected = { 
  id: 1,
  title: "new"
}.to_json

# replace with action name / params as necessary, perhaps also passing "id: 1"?
get :v, format: "json"
response.body.should == @expected
Nick B
  • 7,639
  • 2
  • 32
  • 28
  • The json objects will be present in the link i need to connect to the URL and then validate – jos Jul 30 '16 at 04:21