rspec
Nothing to display jet.
Nothing to display jet.
Could not resist to share it :)
Just see video: http://vimeo.com/32424001
Site: http://mattsears.com/articles/2011/11/16/nyan-cat-rspec-formatter Screenshot under cut
The gem database_cleaner is a beast and may eat some seconds out of your #rspec test suite. By using a simpler approach you can save up some time. More under the cut
Zeus preloads your app and when you run console, generate or rspec tasks it loads much faster - less than a second! More under the cut
Checkout new website which aggregates a lots of information about testing, best practices, examples, book, presentations and a lot more.
I don't like cucumber and scenarios for development, but using it for introducing application features for customers with #capybara produce awesome effect. More under the cut
If you need to confirm or cancel alert dialog in test cases you should do something like this:
# actions.html.slim
= link_to 'EXTERMINATE!!!', planet_path, method: :delete,
data: { confirm: 'Are you sure?' }
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 ....
#shoulda - is a #gem by #thoughtbot. It provides helpers for your #rspec or unit-tests like this:
# account_spec.rb
it { should belong_to(:user) }
it { should belong_to(:project) }
it { should validate_presence_of(:user) }
it { should validate_presence_of(:project) }
it { should validate_uniqueness_of(:project_id).scoped_to(:user_id) }
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
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 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