Are your tests order-dependent? Tired of all those randomly failing specs? Can't be bothered to use Timecop? Just give up and surrender. But at least use a proper syntax.
Introducing the maybe syntax for RSpec.
Add this line to your application's Gemfile:
gem 'spec-me-maybe'And then execute:
$ bundleOr install it yourself as:
$ gem install spec-me-maybeThen, in your spec_helper.rb file:
require 'rspec/maybes'The "maybe" syntax looks and feels almost exactly like the "expect" syntax:
describe User do
describe '#initialize' do
let(:user) { User.new(name: 'David Celis') }
it 'should set up a name' do
maybe(user.name).will eq 'David Celis'
end
it 'probably should not raise any sort of error' do
maybe { user }.will_not raise_error
end
end
endWhereas expect would set up an RSpec::Expectation, maybe will instead set up an RSpec::Maybe. Also like Expectations, Maybes might or might not pass. In this case, however, it will pass randomly. But hey, maybe your Expectations were like that too.
If your colleagues' complaints of broken specs are totally bullshit because you're super sure they work on your machine, we've got you covered. Here's the same above example, but it'll totally always pass:
describe User do
describe '#initialize' do
let(:user) { User.new(name: 'David Celis') }
it 'should set up a name' do
maybe(user.name).will eq('David Celis').on_my_machine
end
it 'probably should not raise any sort of error' do
maybe { user }.will_not raise_error.on_my_machine
end
end
end- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request