Fivemat makes your spec's output format pretty by releu

757fb0d5ec7560b6f25f5bd98eadc020?size=52

Specs output groups by top describe and shows failure specs immediately.

Authentication ..
User ........................F.
  1) User#all_requests 
     Failure/Error: it { should == [request] }
       expected: [#<Request id: 1>]
            got: [] (using ==)
       Diff:
       @@ -1,2 +1,2 @@
       -[#<Request id: 1">]
       +[]
     # ./spec/models/user_spec.rb:45:in `block (3 levels) in <top (required)>'
Dashboard ....

Setup

RSpec ordering of declarations by releu

757fb0d5ec7560b6f25f5bd98eadc020?size=52

Today I had got strange behavior of #rspec while writing tests with #capybara.

This doesn't work:

context 'for unauthorized user' do
  before { visit all_path }
  let!(:tags) { 5.times.map { create(:tag) } }

  it 'should show popular tags' do
    Tag.popular.each do |tag|
      sidebar.should have_link(tag.with_sign)
    end
  end
end

More under the cut

How to test mailer sender by releu

757fb0d5ec7560b6f25f5bd98eadc020?size=52

I had a problem:

it 'should send confirmation email' do
  review = build(:review)
  ReviewMailer.should_receive(:confirmation).with(review)
  review.save
end

Didn't work and returns undefined method `deliver' for nil:NilClass

Then I found a gist with solution! More under the cut

The difference between let and let! in the RSpec by releu

757fb0d5ec7560b6f25f5bd98eadc020?size=52

The let blocks are lazy-evaluated and the let! blocks are always evaluated. So simple..

describe(:let) do
  let(:smth) { Smth.create! }
  it { Smth.count.should == 0 }
  it { smth; Smth.count.should == 1 }
end

describe(:let!) do
  let!(:smth) { Smth.create! }
  it { Smth.count.should == 1 }
end

I didn't know about it and was nervous a lot. #ruby #rspec