2011-01-14 6 views
0

私たちはコントローラで作業しています。これはちょっとこのように見えます:RSpec 2のRailsコントローラの応答でXMLタグを検索するにはどうすればよいですか?

class ArticlesController < ApplicationController 
    respond_to :xml 

    def show 
    respond_with(Article.find(params[:id])) 
    end 
end 

特定のフィールドが結果に表示されることを期待したいと思います。私たちは、このやってみました:

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 

を得たが、この:だからhave_selectorは適切ではない

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)>' 

を。 have_tagも動作しません。これを書く正しい方法は何ですか?

答えて

0

することは、{(: "あなたのクリック率を向上させるために3527 can'tフェイルのヒント" "タイトル"、コンテンツ=>)をhave_selectorなければならない}

を試してみてくださいおっと

+0

、それはタイプミスでした。私は 'have_selector'を意味しました。ちょうどそれが私に 'NoMethodError'を与えることを確認しました。私は質問を更新しました。 – Peeja

関連する問題