How can I search for an XML tag in the response of a Rails controller with RSpec 2?
We're working on a controller. It looks a bit like this:
class ArticlesController < A开发者_开发知识库pplicationController
respond_to :xml
def show
respond_with(Article.find(params[:id]))
end
end
We'd like to expect that a certain field shows up in the result. We tried doing this:
require 'spec_helper'
describe ArticlesController do
describe "#show" do
let(:article) { Article.create!(:title => "3,527 can't-fail tips to improve your clickthrough rates.") }
subject { get :show, :id => article.id; response }
it { should have_selector("title", :text => "3,527 can't-fail tips to improve your clickthrough rates.") }
end
end
but got this:
Failures:
1) ArticlesController#show
Failure/Error: it { should have_selector("title", :text => "3,527 can't-fail tips to improve your clickthrough rates.") }
NoMethodError:
undefined method `has_content?' for #<ActionController::TestResponse:0x00000100e29770>
# ./spec/controllers/articles_controller_spec.rb:7:in `block (3 levels) in <top (required)>'
So have_selector
isn't right. And have_tag
doesn't work either. What's the right way to write this?
Try
it { should have_selector("title", :content => "3,527 can't-fail tips to improve your clickthrough rates.") }
精彩评论