Giter VIP home page Giter VIP logo

spec-me-maybe's Introduction

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

spec-me-maybe's People

Contributors

davidcelis avatar mipearson avatar

Stargazers

Yasin ATEŞ avatar Nick Cannariato avatar David Zhang avatar Garen Torikian avatar Clinton avatar Dale Palmer avatar Tom Leskin avatar Dylan C. Kendal avatar Volodya Sveredyuk avatar Angus H. avatar Paco Benavent avatar Mateusz Tuński avatar Hunter avatar Yurii avatar Thomas Klemm avatar Damian Esteban avatar Pavel Kalvoda avatar Indro De avatar Yuri Veremeyenko avatar Serhii Ponomarov avatar Serhii Herniak avatar Vladimir Vinnikov avatar Alex Musayev avatar  avatar Anthony Panozzo avatar Muescha avatar Christoph Geschwind avatar Anastasia Burchalova avatar Tomas Markauskas avatar Oleh Khomei avatar Heber Uriegas avatar Petr Stepchenko avatar Jamie Schembri avatar Mike Groseclose avatar Marin avatar Mark Bell avatar Pascal avatar Antoine P. avatar  avatar Dmitry Gritsay avatar  avatar Oscar Rendon avatar Ciaran Downey avatar Todd Bealmear avatar Adam Hill avatar Hakan Ensari avatar John Kelly avatar Josh Hoff avatar Jon Austin avatar David Lee avatar Tu Hoang avatar Cole Willsea avatar Gursimran Singh avatar Peter Souter avatar Jacky Alciné avatar Davide D'Ippolito avatar Finbarr Taylor avatar  avatar  avatar Hady Mahmoud avatar Ben Coppock avatar Michael Irey avatar Mitch Dempsey avatar Mihail Szabolcs avatar Kevin McAlear avatar Katie Leonard avatar Jean Pierre avatar Leonardo Bighetti avatar  avatar adamb avatar David Gonzalez avatar Cody Tatman avatar Craig Spaeth avatar Georgios Giannoutsos Barkas avatar Alex avatar Daniel Levenson avatar Kevin avatar Wes Hargrove avatar Bilal Quadri avatar Aaron Miller avatar Pascal Sygnet avatar Fela avatar Stephen Celis avatar Jon Jensen avatar Daniel Garman avatar Heneli Kailahi avatar Deniz Kural avatar John Paul Ashenfelter avatar Joseph Bridgwater-Rowe avatar Cakey | Buddy Magsipoc avatar Steve Hill avatar Nick Urban avatar C.J. Bordeleau / r4v3n avatar Freddy Kelly avatar Damián Silvani avatar Serene Careaga avatar James Kassemi avatar Juan Pablo Ortiz avatar Robert Shedd avatar Joseph Le Brech avatar

Watchers

 avatar James Cloos avatar Julien Vitard avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.