我有一个显示欢迎消息或视频的视图,具体取决于是否@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
没有传递给视图?