Skip to content
Introduces the `maybe` syntax to RSpec.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
spec
.gitignore
.rspec
.travis.yml
Gemfile
LICENSE.txt
README.md
Rakefile
spec-me-maybe.gemspec

README.md

spec-me-maybe Build Status

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.

Installation

Add this line to your application's Gemfile:

gem 'spec-me-maybe'

And then execute:

$ bundle

Or install it yourself as:

$ gem install spec-me-maybe

Then, in your spec_helper.rb file:

require 'rspec/maybes'

RSpec.configure do |config|
  config.expect_with :rspec do |expectations|
    # Enable the `maybe` syntax from spec-me-maybe, e.g.:
    #   maybe(actual).will eq(expected)
    expectations.syntax = :maybe
  end
end

Usage

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
end

Whereas expect would set up an RSpec::Expectations::ExpectationTarget, maybe will instead set up an RSpec::Maybe::MaybeTarget. Like expectations, maybes may or may not fail. In the case of maybes, however, they will fail randomly regardless of your code. 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 above example again, but this time 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

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request
You can’t perform that action at this time.