ruby on rails - rspec: ignoring format while testing a view? -
i'm writing test views. happen have html , json views 1 action, , didn't figured out how can force rspec use given format.
currently minimized code following:
# cat spec/views/services/index.json.jbuilder_spec.rb require 'spec_helper' describe "services/index" let(:services) { 3.times.map { factorygirl.create(:service) } } before(:each) { assign(:services, services) } let(:resp) render template: 'services/index', format: :json # note format here json.parse(response.body, simbolize_names: true) end it("should array") { resp.should be_kind_of(array) } end
but stills rendering html code. i'm getting error
failure/error: json.parse(response.body, simbolize_names: true) json::parsererror: 757: unexpected token @ '<h1>listing services</h1> [cut rest of html]
my json view simple
# cat app/views/services/index.json.jbuilder json.array! @services, *service.json_attributes
and first 5 lines of html view is
# cat app/views/services/index.html.haml | head -5 %h1 listing services %table %tr %th logo
if try pass format in render template, like
render template: 'services/index.json'
i got following:
deprecation warning: passing template handler in template name deprecated. can remove handler name or pass render
my rspec version 2.13.1, running on ruby 2.0.
just curious:
render template: 'services/index', formats: :json
work well?
notice formats s in end.
Comments
Post a Comment