Skip to content

Instantly share code, notes, and snippets.

View dchelimsky's full-sized avatar

David Chelimsky dchelimsky

  • Retired
  • Chicago, IL, USA
View GitHub Profile
RSpec::Core::FilterManager
#include
merges inclusions
overrides previous inclusions with (via merge)
deletes matching opposites
with :locations
clears previous inclusions
does nothing when :locations previously set
with :line_numbers
clears previous inclusions
# 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
@dchelimsky
dchelimsky / example-10.rb
Created May 15, 2012 00:26
More source examples for blog on explicit use of subject
describe Article do
def article; Article.new :title => "Lorem ipsum"; end
it "has a title" do
article.title.should eq("Lorem ipsum")
end
end
@dchelimsky
dchelimsky / example-1.rb
Created May 14, 2012 03:03
Source examples for blog on explicit use of subject
describe Article do
it { should validate_presence_of(:title) }
end
class Article < ActiveRecord::Base
validates_presence_of :title
has_many :comments
end
@dchelimsky
dchelimsky / 1_let.rb
Created March 29, 2012 23:33 — forked from ryanb/1_let.rb
let vs def
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
@dchelimsky
dchelimsky / output.txt
Created March 16, 2012 15:28
RSpec is not the reason your rails test suite is slow
[david: compare]$ # at this point we have a stock rails app with no minitest tests and one pending rspec example
[david: compare]$
[david: compare]$ time rake test
Run options:
# Running tests:
Finished tests in 0.030419s, 0.0000 tests/s, 0.0000 assertions/s.
@dchelimsky
dchelimsky / output.txt
Created March 16, 2012 10:54
What happens when objects implement == incorrectly
$ rspec example_spec.rb
F
Failures:
1) Pessimist never thinks its equal, even to itself
Failure/Error: pessimist.should eq(pessimist)
expected: #<Pessimist:0x007fb82a9bae80>
got: #<Pessimist:0x007fb82a9bae80>
@dchelimsky
dchelimsky / pending_and_before_examples.rb
Created December 11, 2011 15:24
Interaction between pending and before hooks in RSpec
describe Something do
before(:each) do
do_something_before
end
it "does one thing" do
# before will run for this example because rspec doesn't know it is pending
# until the example is eval'd
pending
end
describe "GET /agents.json" do
it_behaves_like "API controller", :params => { ... }, :environment => { ... }
end