0

@videoが定義されているかどうかに応じて、ウェルカム メッセージまたはビデオのいずれかを表示するビューがあります。@videoビューのいくつかのテストを作成しようとしていますが、が定義されているケースをカバーする方法がわかりません。

ビューは次のとおりです。

<div class="container" id="contents">
  <% unless defined? @video %>
    <div class="hero-unit">
      <h1>
        Khan-O-Tron<br />
        <small>Khan Academy has a lot of great videos. So many, in fact, that choosing just one is kind of annoying. Click the button below and let us choose one for you!</small>
      </h1><br />
      <a class="btn btn-large btn-success" href="/random">Get Started By Watching A Tutorial</a>
    </div>
  <% else %>
    <div class="hero-unit">
      <h1><%= @video.title %><br /> <small><%= @video.description %></small></h1>
      <br />
      <%= raw @video.get_embed_code %>
    </div>
  <% end %>
</div>

ここに私のテストがあります:

require 'spec_helper'

describe "[Static Pages]" do
  describe "GET /" do
    before { visit root_path }
    subject { page }

    describe "#hero-unit" do
      describe "with @video not defined" do
        it "should have an H1 tag with the text 'Khan-O-Tron'." do
          should have_selector ".hero-unit h1", text: "Khan-O-Tron"
        end
        it "should have an H1 small tag with a description of our product." do
          should have_selector ".hero-unit h1 small", text: "Khan Academy has a lot of great videos. So many, in fact, that choosing just one is kind of annoying. Click the button below and let us choose one for you!"
        end
        it "should have a link to /random with the text 'Get Started By Watching A Tutorial'" do
          should have_link "Get Started By Watching A Tutorial", href: "/random"
        end
      end
      describe "with @video defined" do

        before { @video = FactoryGirl.create(:video) }

        it "should have an H1 tag with the video's title" do
          should have_selector ".hero-unit h1", text: @video.title
        end
        it "should have an H1 small tag with the video's description" do
          should have_selector ".hero-unit h1 small", text: @video.description
        end
        it "should have the video embedded in the page" do
          should have_selector "iframe"
        end
      end
    end
  end
end

@videoを使用して定義した変数がFactoryGirlビューに渡されないのはなぜですか?

4

1 に答える 1