Skip to content

Instantly share code, notes, and snippets.

@cupakromer
Created August 18, 2014 21:14
Show Gist options
  • Select an option

  • Save cupakromer/68c6ad077d5d535211f4 to your computer and use it in GitHub Desktop.

Select an option

Save cupakromer/68c6ad077d5d535211f4 to your computer and use it in GitHub Desktop.
Generatron slide updates for RSpec 3 goodies (https://github.com/jessitron/generatron)

Some suggested updates to the slides in https://github.com/jessitron/generatron. These suggestions are based off of the array of built-in matchers that RSpec 3 provides (https://www.relishapp.com/rspec/rspec-expectations/v/3-0/docs/built-in-matchers). As well as the composability / compounding features now available: http://myronmars.to/n/dev-blog/2014/01/new-in-rspec-3-composable-matchers

Slide 24

expect(influence.relevance).to (be <= 100).and (be >= 0)

You can also just make this a range matcher:

def be_in_range(range)
  matcher = (be >= range.begin)
  if range.exclude_end?
    matcher = matcher.and(be < range.end)
  else
    matcher = matcher.and(be <= range.end)
  end
  matcher
end

Then in the spec:

expect(influence.relevance).to be_in_range(0..100)

Slide 49 / 50

When comparing hashes or partial hashes, the include and it's alias a_hash_including, and a_collection_including are helpful. I feel like the posted slides are slightly different from what I saw at SCRC14; though it's probably my memory that is off. It doesn't work as well in the PDF slides, but I hope it helps you at work. 😺

# Singular
expect(actual).to eq(event: search)

# There's at least one
expect(actual).to include(event: search)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment