Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Include require 'spec_helper' in README code examples, fixes #581 #582

Merged
merged 1 commit into from

3 participants

@jessicalevine

Adds require 'spec_helper' to the beginning of the code examples in README. See more reasoning at #581. I know it seems a bit like unnecessary repetition of code, but it should help prevent developers from copying test outlines from the documentations and getting cryptic error messages as to why the test won't function.

@travisbot

This pull request passes (merged 72ceb3c into 274ae67).

@alindeman alindeman merged commit e60f6e2 into rspec:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 30, 2012
This page is out of date. Refresh to see the latest.
Showing with 10 additions and 0 deletions.
  1. +10 −0 README.md
View
10 README.md
@@ -108,6 +108,7 @@ intent is to specify one or more request/response cycles from end to end using
a black box approach.
```ruby
+require 'spec_helper'
describe "home page" do
it "displays the user's username after successful login" do
user = User.create!(:username => "jdoe", :password => "secret")
@@ -128,6 +129,7 @@ This example uses only standard Rails and RSpec API's, but many RSpec/Rails
users like to use extension libraries like FactoryGirl and Capybara:
```ruby
+require 'spec_helper'
describe "home page" do
it "displays the user's username after successful login" do
user = FactoryGirl.create(:user, :username => "jdoe", :password => "secret")
@@ -163,6 +165,7 @@ tests.
## with fixtures
```ruby
+require 'spec_helper'
describe WidgetsController do
describe "GET index" do
fixtures :widgets
@@ -178,6 +181,7 @@ end
## with a factory
```ruby
+require 'spec_helper'
describe WidgetsController do
describe "GET index" do
it "assigns all widgets to @widgets" do
@@ -192,6 +196,7 @@ end
## with stubs
```ruby
+require 'spec_helper'
describe WidgetsController do
describe "GET index" do
it "assigns all widgets to @widgets" do
@@ -236,6 +241,7 @@ functional tests, you can tell controller groups to render the views in the
app with the `render_views` declaration:
```ruby
+require 'spec_helper'
describe WidgetsController do
render_views
# ...
@@ -260,6 +266,7 @@ assigns(:widgets).should eq(expected_value)
View specs live in spec/views, and mix in ActionView::TestCase::Behavior.
```ruby
+require 'spec_helper'
describe "events/index" do
it "renders _event partial for each event" do
assign(:events, [stub_model(Event), stub_model(Event)])
@@ -360,6 +367,7 @@ rendered.should xxx
Model specs live in spec/models.
```ruby
+require 'spec_helper'
describe Article do
describe ".recent" do
it "includes articles published less than one week ago" do
@@ -385,6 +393,7 @@ end
Routing specs live in spec/routing.
```ruby
+require 'spec_helper'
describe "routing to profiles" do
it "routes /profile/:username to profile#show for username" do
{ :get => "/profiles/jsmith" }.should route_to(
@@ -412,6 +421,7 @@ Provides a `helper` object which mixes in the helper module being spec'd, along
with `ApplicationHelper` (if present).
```ruby
+require 'spec_helper'
describe EventsHelper do
describe "#link_to_event" do
it "displays the title, and formatted date" do
Something went wrong with that request. Please try again.