Giter VIP home page Giter VIP logo

spec_cat's Introduction

Build Status Coverage Status Code Climate Dependency Status Gem Version

schrodingersbox/spec_cat

This gem contains trivial matchers to make RSpecs a bit more effective and less annoying.

  • eql_file
  • have_a_spec
  • include_module
  • pass_rubocop
  • validates_with

It also provides rake commands

  • rake spec_cat:accept
  • spec_cat:coverage

NOTE: This gem does not depend on Rails. All paths are relative to cwd, which may be Rails.root or anywhere else.

Getting Started

Add this to your gemfile...

gem 'spec_cat'
gem 'simplecov', :require => false

Add this to your spec_helper.rb...

# Initialize SimpleCov

require 'simplecov'

SimpleCov.start 'rails' do
  add_filter '/vendor/'
  add_filter '/spec/'
end

Matchers

eql_file

eql_file will compare method output to a ground truth file and fail if they are different.

It also writes a .tmp file to replace the old ground truth if it's gone stale.

e.g. #foo produces a gnarly string too nasty to copy and paste into spec code.

 expect(foo).to eql_file('spec/truth/foo.json')

... if it fails for a valid change, you can just....

cp spec/truth/foo.json.tmp spec/truth/foo.json

... and all will be good again.

This mechanism is a bit brittle, but great for big blobs of data.

If you use this, you should add *.tmp to your .gitignore.

have_a_spec

have_a_spec will ensure that any given path has a corresponding spec file to help ensure that you have good coverage.

expect('app/controllers/application_controller.rb').to have_a_spec

... is a good thing to write right after you integrate RSpec.

Here's an example coverage spec...

https://github.com/schrodingersbox/spec_cat/blob/master/spec/coverage_spec.rb

include_module

include_module makes it easy to spec concern inclusion.

it('is taggable') { is_expected.to include_module(Taggable) }

pass_rubocop

pass_rubcop just executes Rubocop and passes or fails based on it's exit status.

it('passes Rubocop') { is_expected.to pass_rubocop }

validates_with

validates_with confirms that an ActiveModel::Validator is being used.

it('validates numbers') { is_expected.to validate_with(NumberValidator) }

Rake Tasks

spec_cat:accept

rake spec_cat:accept runs all specs and causes the eql_file matcher to overwrite the ground truth files, rather than output .tmp files.

This is convenient when a code change impacts a large number of ground truth files, but is also risky, as it may allow an incorrect change to become ground truth.

spec_cat:coverage

rake spec_cat:coverage runs all specs and then opens the coverage report if all the specs pass.

Reference

Version History

Credits

Thanks to Filip Bartuzi and Otavio Medeiros for publishing their gists of the validate_with matcher!

spec_cat's People

Contributors

rdh avatar

Watchers

 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.