This file contains 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
# Note the differences between this and https://gist.github.com/2938822 are that | |
# we're making 10k groups with 1 example each vs 1 group w/ 10k examples, and the | |
# rspec example uses "should eq" instead of "should ==" | |
if $0 =~ /rspec$/ | |
10_000.times do |i| | |
describe "loltest #{i}" do | |
it "does #{i}" do | |
i.should eq i | |
end |
This file contains 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
desc "A user's comment" do | |
let(:user) { User.create! name: "John" } | |
let(:comment) { user.comments.create! } | |
it "delegates to user's name" do | |
comment.name.should eq(user.name) | |
end | |
end |
This file contains 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 "GET /agents.json" do | |
it_behaves_like "API controller", :params => { ... }, :environment => { ... } | |
end |
This file contains 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
# The following is an example of how you might use shared content to reduce the | |
# duplication in https://gist.github.com/1128108. I prefer to avoid examples | |
# that use `should respond_to`, as it specifies structure rather than behavior. | |
# I'd recommend specifying something about what happens when the message is | |
# sent, e.g. subject.some_method.should eq(some_value). That implicitly | |
# specifies that the object responds to some_method, and provides more useful | |
# direction/information about how the object should behave. | |
# | |
# That said ... |
This file contains 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 Card do | |
describe "#value" do | |
context "Two of Hearts" do | |
subject { Card.new("2H") } | |
its(:value) { should == 2 } | |
end | |
describe "Face Cards" do | |
context "King of Clubs" do |
This file contains 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 Subscription do | |
describe '#api_representation' do | |
let(:record) { new_valid_record } | |
before(:each) do | |
record.engine_variants.first.should respond_to(:api_representation) | |
record.engine_variants.first.stub(api_representation: 'ev_api_representation') | |
record.url_fragments.first.should respond_to(:api_representation) | |
record.url_fragments.first.stub(api_representation: 'uf_api_representation') |
This file contains 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
# ------------------------------------- | |
# DECLARATION | |
# using strings for explicit inclusion | |
shared 'logged in as admin' do | |
before { login_as admin_user } | |
end | |
shared 'a model with a slug' do | |
it 'sets the slug column upon initialization' do |
This file contains 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
require 'spec_helper' | |
describe ArticlesController, :type => :controller do | |
# ^^ :type => :controller is not necessary if the file is in spec/controllers | |
describe "GET index" do | |
# ^^ The describe method creates an example group. ^^ | |
get :index | |
# ^^ The get method is exposed to an example. | |
response.should be_successful | |
end |
This file contains 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
module MyModule | |
def some_method | |
super | |
rescue SystemStackError => e | |
puts "you're including MyModule more than once" | |
end | |
end | |
class MyBaseClass; end |
This file contains 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 Controller do | |
context "create" do | |
it "saves the model" do | |
model = Model.new | |
Model.stub(:new).and_return(model) | |
model.should_receive(:save) | |
post :create | |
end | |
end | |
end |
NewerOlder