0.06
No commit activity in last 3 years
No release in over 3 years
Adds the `maybe` syntax to RSpec: describe Thing do it 'is maybe equal to another thing' do maybe(Thing.new).will eq(another_thing) # Passes sometimes. Maybe. end end
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 3.1

Runtime

 Project Readme

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