spec_cat 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +21 -0
- data/README.md +92 -0
- data/Rakefile +3 -0
- data/lib/spec_cat/matchers/eql_file.rb +28 -0
- data/lib/spec_cat/matchers/have_a_spec.rb +33 -0
- data/lib/spec_cat/matchers/include_module.rb +23 -0
- data/lib/spec_cat/railtie.rb +12 -0
- data/lib/spec_cat/version.rb +3 -0
- data/lib/spec_cat.rb +23 -0
- data/lib/tasks/spec_cat.rake +14 -0
- metadata +133 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 04e83ac3e75c89fc69549058557706a0bbb2a2bc
|
4
|
+
data.tar.gz: ec408995fdd89b1cf3a66a58cbf0e5f409f345d4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bc63fa25af06f5143a036a6320244d0747c05d0ca14ee23512bf947cf4b067c30dd0eb7de949491099e4f3f3a1c5f68267af3b1f202f6a3f4c195e2128178875
|
7
|
+
data.tar.gz: 060a2010c929c34020b246c211b7a2bded606bd8b4aa14d385f70480a745a6b4fdb6a503c3daf4c78a2513b1fb0f29bd74a2714f9670eb2f30e90fcfd0c66738
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) 2012 SchrodingersBox.com
|
2
|
+
MIT License
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/schrodingersbox/spec_cat.svg?branch=master)](https://travis-ci.org/schrodingersbox/spec_cat)
|
2
|
+
[![Coverage Status](https://coveralls.io/repos/schrodingersbox/spec_cat/badge.png?branch=master)](https://coveralls.io/r/schrodingersbox/spec_cat?branch=master)
|
3
|
+
[![Code Climate](https://codeclimate.com/github/schrodingersbox/spec_cat.png)](https://codeclimate.com/github/schrodingersbox/spec_cat)
|
4
|
+
[![Dependency Status](https://gemnasium.com/schrodingersbox/spec_cat.png)](https://gemnasium.com/schrodingersbox/spec_cat)
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/spec_cat.png)](http://badge.fury.io/rb/spec_cat)
|
6
|
+
|
7
|
+
# schrodingersbox/spec_cat
|
8
|
+
|
9
|
+
This gem contains trivial matchers to make RSpecs a bit more effective and annoying.
|
10
|
+
|
11
|
+
* eql_file
|
12
|
+
* have_a_spec
|
13
|
+
|
14
|
+
NOTE: This gem does not depend on Rails. All paths are relative to cwd, which
|
15
|
+
may be Rails.root or anywhere else.
|
16
|
+
|
17
|
+
## Getting Started
|
18
|
+
|
19
|
+
Add this to your gemfile...
|
20
|
+
|
21
|
+
gem 'spec_cat', :git => 'https://github.com/schrodingersbox/spec_cat.git'
|
22
|
+
|
23
|
+
## Matchers
|
24
|
+
|
25
|
+
### eql_file
|
26
|
+
|
27
|
+
`eql_file` will compare method output to a ground truth file and fail if they
|
28
|
+
are different.
|
29
|
+
|
30
|
+
It also writes a .tmp file to replace the old ground truth if it's gone stale.
|
31
|
+
|
32
|
+
e.g. #foo produces a gnarly string too nasty to copy and paste into code.
|
33
|
+
|
34
|
+
foo.should eql_file( 'spec/data/foo.json' )
|
35
|
+
|
36
|
+
... if it fails for a valid change, you can just....
|
37
|
+
|
38
|
+
cp spec/truth/foo.json.tmp spec/truth/foo.json
|
39
|
+
|
40
|
+
... and all will be good again.
|
41
|
+
|
42
|
+
This mechanism is a bit brittle, but great for big blobs of data.
|
43
|
+
|
44
|
+
If you use this, you should add `*.tmp` to your .gitignore.
|
45
|
+
|
46
|
+
### have_a_spec
|
47
|
+
|
48
|
+
`have_a_spec` will ensure that any given path has a corresponding spec file to
|
49
|
+
help ensure that you have good coverage.
|
50
|
+
|
51
|
+
'app/controllers/application_controller.rb'.should have_a_spec
|
52
|
+
|
53
|
+
... is a good thing to write right after you integrate RSpec.
|
54
|
+
|
55
|
+
Here's an example coverage spec...
|
56
|
+
|
57
|
+
<https://github.com/schrodingersbox/spec_cat/blob/master/spec/coverage_spec.rb>
|
58
|
+
|
59
|
+
### include_module
|
60
|
+
|
61
|
+
`include_module` makes it easy to spec concern inclusion.
|
62
|
+
|
63
|
+
it( 'is Taggable' ) { should include_module( Taggable ) }
|
64
|
+
|
65
|
+
## Rake Tasks
|
66
|
+
|
67
|
+
### spec_cat:accept
|
68
|
+
|
69
|
+
`rake spec_cat:accept` runs all specs and causes the eql_file matcher to overwrite
|
70
|
+
the ground truth files, rather than output .tmp files.
|
71
|
+
|
72
|
+
This is convenient when a code change impacts a large number of ground truth files,
|
73
|
+
but is also risky, as it may allow an incorrect change to become ground truth.
|
74
|
+
|
75
|
+
### spec_cat:coverage
|
76
|
+
|
77
|
+
`rake spec_cat:coverage` runs all specs and then opens the coverage report if all the
|
78
|
+
specs pass.
|
79
|
+
|
80
|
+
## Reference
|
81
|
+
|
82
|
+
* [RSpec](https://github.com/rspec/rspec)
|
83
|
+
* [Testing Rake Tasks with RSpec](http://www.philsergi.com/2009/02/testing-rake-tasks-with-rspec.html)
|
84
|
+
* [Nathan Humbert's Blog: Rails 3: Loading rake tasks from a gem](http://blog.nathanhumbert.com/2010/02/rails-3-loading-rake-tasks-from-gem.html)
|
85
|
+
* [Publishing your gem](http://guides.rubygems.org/publishing/)
|
86
|
+
|
87
|
+
## TODO
|
88
|
+
|
89
|
+
* Fix include_module - only get class if arg is not already a class
|
90
|
+
* Add more matchers
|
91
|
+
|
92
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# eql_file.rb
|
2
|
+
#
|
3
|
+
# Confirms that an in-memory string matches a ground truth file.
|
4
|
+
# Exports the actual value as a .tmp file as a side effect.
|
5
|
+
#
|
6
|
+
# 'cp foo/bar.tmp foo/bar' to correct valid test failures.
|
7
|
+
|
8
|
+
RSpec::Matchers.define :eql_file do |expected_path|
|
9
|
+
|
10
|
+
description do
|
11
|
+
"match the contents of #{expected}"
|
12
|
+
end
|
13
|
+
|
14
|
+
failure_message_for_should do |actual|
|
15
|
+
"expected that #{actual} would match the contents of #{expected}"
|
16
|
+
end
|
17
|
+
|
18
|
+
failure_message_for_should_not do |actual|
|
19
|
+
"expected that #{actual} would not match the contents of #{expected}"
|
20
|
+
end
|
21
|
+
|
22
|
+
match do |actual|
|
23
|
+
extension = SpecCat.accept? ? '' : '.tmp'
|
24
|
+
SpecCat.write( expected_path + extension, actual )
|
25
|
+
actual == SpecCat.read( expected_path )
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# have_a_spec.rb
|
2
|
+
#
|
3
|
+
# Confirms that a given file path has a corresponding spec file.
|
4
|
+
|
5
|
+
RSpec::Matchers.define :have_a_spec do
|
6
|
+
|
7
|
+
description do
|
8
|
+
'has a spec file'
|
9
|
+
end
|
10
|
+
|
11
|
+
match do |path|
|
12
|
+
File.exists?( spec_file_for( path ) )
|
13
|
+
end
|
14
|
+
|
15
|
+
failure_message_for_should do |path|
|
16
|
+
"expected #{path} to have spec at #{spec_file_for( path )}"
|
17
|
+
end
|
18
|
+
|
19
|
+
failure_message_for_should_not do |path|
|
20
|
+
"expected #{path} to not have spec at #{spec_file_for( path )}"
|
21
|
+
end
|
22
|
+
|
23
|
+
def spec_file_for( path )
|
24
|
+
basename = File.basename( path, '.rb' ) + '_spec.rb'
|
25
|
+
|
26
|
+
dirname = File.dirname( path )
|
27
|
+
dirname.gsub!( /^app/, 'spec' )
|
28
|
+
dirname.gsub!( /^lib/, 'spec/lib' )
|
29
|
+
|
30
|
+
return File.join( dirname, basename )
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# include_module.rb
|
2
|
+
#
|
3
|
+
# Confirms that the subject includes the expected module
|
4
|
+
|
5
|
+
RSpec::Matchers.define :include_module do |expected_module|
|
6
|
+
|
7
|
+
description do
|
8
|
+
"includes #{expected}"
|
9
|
+
end
|
10
|
+
|
11
|
+
failure_message_for_should do |subject|
|
12
|
+
"expected that #{subject.class} would include #{expected}"
|
13
|
+
end
|
14
|
+
|
15
|
+
failure_message_for_should_not do |subject|
|
16
|
+
"expected that #{subject.class} would not include #{expected}"
|
17
|
+
end
|
18
|
+
|
19
|
+
match do |subject|
|
20
|
+
subject.class.included_modules.include?( expected_module )
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
data/lib/spec_cat.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
|
3
|
+
require 'spec_cat/matchers/eql_file'
|
4
|
+
require 'spec_cat/matchers/have_a_spec'
|
5
|
+
require 'spec_cat/matchers/include_module'
|
6
|
+
|
7
|
+
require 'spec_cat/railtie' if defined?(Rails)
|
8
|
+
|
9
|
+
module SpecCat
|
10
|
+
|
11
|
+
def self.accept?
|
12
|
+
!ENV[ 'SPEC_CAT_ACCEPT' ].nil?
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.write( path, content )
|
16
|
+
File.open( path,'wb' ) { |io| io.write content }
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.read( path )
|
20
|
+
File.open( path, 'rb' ) { |io| io.read }
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
namespace :'spec_cat' do
|
2
|
+
|
3
|
+
desc 'Run rspec and accept all ground truth file changes'
|
4
|
+
task :accept do
|
5
|
+
ENV[ 'SPEC_CAT_ACCEPT' ] = '1'
|
6
|
+
Kernel.system 'rspec spec'
|
7
|
+
end
|
8
|
+
|
9
|
+
desc 'Run rspec with coverage and open the report'
|
10
|
+
task :coverage do
|
11
|
+
Kernel.system 'rspec spec && open coverage/index.html'
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: spec_cat
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rich Humphrey
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2012-09-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.14'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 2.14.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '2.14'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.14.0
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: rails
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '4.0'
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 4.0.0
|
43
|
+
type: :development
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '4.0'
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 4.0.0
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: simplecov
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - "~>"
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0.8'
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 0.8.2
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0.8'
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: 0.8.2
|
73
|
+
- !ruby/object:Gem::Dependency
|
74
|
+
name: coveralls
|
75
|
+
requirement: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - "~>"
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0.7'
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.7.0
|
83
|
+
type: :development
|
84
|
+
prerelease: false
|
85
|
+
version_requirements: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.7'
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: 0.7.0
|
93
|
+
description: Adds a few useful RSpec matchers
|
94
|
+
email: rich@schrodingersbox.com
|
95
|
+
executables: []
|
96
|
+
extensions: []
|
97
|
+
extra_rdoc_files: []
|
98
|
+
files:
|
99
|
+
- MIT-LICENSE
|
100
|
+
- README.md
|
101
|
+
- Rakefile
|
102
|
+
- lib/spec_cat.rb
|
103
|
+
- lib/spec_cat/matchers/eql_file.rb
|
104
|
+
- lib/spec_cat/matchers/have_a_spec.rb
|
105
|
+
- lib/spec_cat/matchers/include_module.rb
|
106
|
+
- lib/spec_cat/railtie.rb
|
107
|
+
- lib/spec_cat/version.rb
|
108
|
+
- lib/tasks/spec_cat.rake
|
109
|
+
homepage: https://github.com/schrodingersbox/spec_cat
|
110
|
+
licenses:
|
111
|
+
- MIT
|
112
|
+
metadata: {}
|
113
|
+
post_install_message:
|
114
|
+
rdoc_options: []
|
115
|
+
require_paths:
|
116
|
+
- - lib
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
requirements: []
|
128
|
+
rubyforge_project:
|
129
|
+
rubygems_version: 2.2.0
|
130
|
+
signing_key:
|
131
|
+
specification_version: 4
|
132
|
+
summary: RSpec support library
|
133
|
+
test_files: []
|