This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe "routing to profiles" do | |
it "routes /profile/:username to profile#show for username" do | |
{ :get => "/profiles/jsmith" }.should route_to( | |
:controller => "profiles", | |
:action => "show", | |
:username => "jsmith" | |
) | |
end | |
it "does not expose a list of profiles" do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe Article do | |
describe ".recent" do | |
it "includes articles published less than one week ago" do | |
article = Article.create!(:published_at => Date.today - 1.week + 1.second) | |
Article.recent.should eq([article]) | |
end | |
it "excludes articles published at midnight one week ago" do | |
article = Article.create!(:published_at => Date.today - 1.week) | |
Article.recent.should be_empty |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe "events/index" do | |
it "renders _event partial for each event" do | |
assign(:events, [stub_model(Event), stub_model(Event)]) | |
render | |
view.should render_template(:partial => "_event", :count => 2) | |
end | |
end | |
describe "events/show" do | |
it "displays the event location" do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#To see the fixtures applied in a practical example, suppose we want to test a chat's application that displays some messages. For this #functionality we write the following spec: | |
#spec/views/chats/show.html.erb_spec.rb | |
describe "views/chats/show.html.erb" do | |
fixture :chats, :messages | |
before(:each) do | |
@chat = chats(:myChat) | |
render "/chats/show.html.erb" | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#with fixtures | |
describe WidgetsController do | |
describe "GET index" do | |
fixtures :widgets | |
it "assigns all widgets to @widgets" do | |
get :index | |
assigns(:widgets).should eq(Widget.all) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe "home page" do | |
it "displays the user's username after successful login" do | |
user = FactoryGirl.create(:user, :username => "jdoe", :password => "secret") | |
visit "/login" | |
fill_in "Username", :with => "jdoe" | |
fill_in "Password", :with => "secret" | |
click_button "Log in" | |
page.should have_selector(".header .username", :text => "jdoe") | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe "home page" do | |
it "displays the user's username after successful login" do | |
user = User.create!(:username => "jdoe", :password => "secret") | |
get "/login" | |
assert_select "form.login" do | |
assert_select "input[name=?]", "username" | |
assert_select "input[name=?]", "password" | |
assert_select "input[type=?]", "submit" | |
end |
NewerOlder