Мы работаем над контроллером. Это выглядит примерно так:
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
но получил это:
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_selector
не прав. И have_tag
тоже не работает. Как правильно написать это?