Module: ThoughtBot::Shoulda::Controller::XML::ClassMethods

Defined in:
lib/shoulda/controller/formats/xml.rb

Instance Method Summary collapse

Instance Method Details

#should_respond_with_xml_for(name = nil) ⇒ Object Also known as: should_respond_with_xml

Macro that creates a test asserting that the controller responded with an XML content-type and that the XML contains <name/> as the root element.



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/shoulda/controller/formats/xml.rb', line 14

def should_respond_with_xml_for(name = nil)
  should "have ContentType set to 'application/xml'" do
    assert_xml_response
  end
  
  if name
    should "return <#{name}/> as the root element" do
      body = @response.body.first(100).map {|l| "  #{l}"}
      assert_select name.to_s.dasherize, 1, "Body:\n#{body}...\nDoes not have <#{name}/> as the root element."
    end
  end
end