2011-12-03 4 views
3

draperを使用してロジックの一部を抽象化する前に、正常に動作した私のビューのrspecテストがあります。ビューはブラウザで正しくレンダリングされますが、テストは失敗します。rspecを使用したDraper-enhancedモデルのテスト

require 'spec_helper' 

describe "articles/index.html.erb" do 
    before(:each) do 
    assign(:articles, [ 
     stub_model(Article, 
     :title => "Title", 
     :slug => "this-is-a-slug", 
     :content => "Content", 
     :excerpt => "Excerpt", 
     :starts_at => "2012-01-10 01:00:00", 
     :ends_at => "2012-01-10 01:30:00", 
     :show_times => true 
    ) 
    ]) 
    render 
    end 

    it "renders a list of articles" do 
    assert_select "h3", :text => "Title".to_s, :count => 8 
    assert_select "div.article_body", :text => "Content".to_s, :count => 8 
    end 
end 

ビューはデコレータ/ article_decorator.rbで定義されているデコレータ方法calendars、への呼び出しが含まれていますが、RSpecのは、私はstub_modelを使用していると思われるので、これを拾っていません。

1) articles/index.html.erb renders a list of articles 
    Failure/Error: render 
    ActionView::Template::Error 
    undefined method `calendars' for #<Article:0x007fd41c68be90> 
    # ./app/views/articles/index.html.erb:4:in `block in _app_views_articles_index_html_erb___1865228919968458103_70274492660680' 
    # ./app/views/articles/index.html.erb:1:in `each' 
    # ./app/views/articles/index.html.erb:1:in `_app_views_articles_index_html_erb___1865228919968458103_70274492660680' 
    # ./spec/views/articles/index.html.erb_spec.rb:85:in `block (2 levels) in <top (required)>' 

テストをもう一度やり直すにはどうすればいいですか? (それとも私の見解をテストする良い方法はありますか?)

答えて

1

私はまだドレイパーを使用し始めていないが、私はこれが動作する必要がありますね:

assign(:articles, [ 
    ArticleDecorator.new(
     stub_model(Article, 
     :title => "Title", 
     :slug => "this-is-a-slug", 
     :content => "Content", 
     :excerpt => "Excerpt", 
     :starts_at => "2012-01-10 01:00:00", 
     :ends_at => "2012-01-10 01:30:00", 
     :show_times => true 
     ) 
    )]) 

今記事が応答デコレータの配列です方法はcalendarsです。

関連する問題