rspec2minitest 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +37 -14
- data/lib/rspec2minitest.rb +21 -10
- data/lib/rspec2minitest/capybara.rb +4 -0
- data/lib/rspec2minitest/paperclip.rb +4 -0
- data/lib/rspec2minitest/test_name.rb +10 -6
- data/lib/rspec2minitest/version.rb +1 -1
- data/rspec2minitest.gemspec +2 -1
- metadata +24 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a69aaff32e17e87b41cafe0f444beeb52e872796
|
4
|
+
data.tar.gz: f89fafaf965c3d270d733c3344c61dfadec5510c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71abb15f5f359e266299928e7ec8d0dd99ee09cdfc6141264e2bb56681229ba5e36a652d2ec379683cd54e54c9766e8c02978b3fc7f0103628dfabd1f0aa3e88
|
7
|
+
data.tar.gz: 1b945657b7e60dbe72cbed7640e1a9701ef84e9a437f7922a229736e6bf34baaf625022d6e370a673f3a07ff5ff2f8d0455aa97e3ba5f0d447ea3dabbbb2a679
|
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/rspec2minitest.png)](http://badge.fury.io/rb/rspec2minitest)
|
2
|
+
[![Dependency Status](https://gemnasium.com/cschramm/rspec2minitest.png)](https://gemnasium.com/cschramm/rspec2minitest)
|
3
|
+
[![Code Climate](https://codeclimate.com/github/cschramm/rspec2minitest.png)](https://codeclimate.com/github/cschramm/rspec2minitest)
|
4
|
+
|
1
5
|
# RSpec2MiniTest
|
2
6
|
|
3
7
|
Provides a generic factory to automatically convert the RSpec matchers of your favorite
|
@@ -6,31 +10,50 @@ It is a generalization of [Jared Ning's capybara_minitest_spec](https://github.c
|
|
6
10
|
|
7
11
|
## Installation
|
8
12
|
|
9
|
-
|
10
|
-
|
13
|
+
# Gemfile
|
11
14
|
gem 'rspec2minitest'
|
12
15
|
|
13
|
-
##
|
16
|
+
## Integrations
|
14
17
|
|
15
18
|
### Capybara
|
16
19
|
|
17
20
|
To create assertions / expectations from all Capybara RSpec matchers add to your `test_helper`:
|
18
21
|
|
19
|
-
require 'rspec2minitest'
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
require 'rspec2minitest/capybara'
|
23
|
+
|
24
|
+
For the `have_text` matcher you can then use:
|
25
|
+
|
26
|
+
# Unit
|
27
|
+
assert_page_has_text(page, text)
|
28
|
+
refute_page_has_text(page, text)
|
29
|
+
|
30
|
+
# Spec
|
31
|
+
it { must_have_text(text) }
|
32
|
+
it { wont_have_text(text) }
|
33
|
+
|
34
|
+
For all matchers see [Capybara/RSpecMatchers](http://rubydoc.info/gems/capybara/Capybara/RSpecMatchers)
|
26
35
|
|
27
36
|
This is exactly what the `capybara_minitest_spec` gem does. If Capybara
|
28
37
|
matchers are the only ones you need to convert, I recommend using that gem.
|
29
38
|
|
30
39
|
### Paperclip
|
31
40
|
|
32
|
-
|
41
|
+
# test_helper
|
42
|
+
require 'rspec2minitest/paperclip'
|
43
|
+
|
44
|
+
The `have_attachment` matcher gets converted to `assert_model_has_attachment`
|
45
|
+
and `must_have_attachment` and their negative counterparts.
|
46
|
+
|
47
|
+
For all matchers see [Paperclip::Shoulda::Matchers](http://rubydoc.info/gems/paperclip/Paperclip/Shoulda/Matchers)
|
48
|
+
|
49
|
+
### Custom integrations
|
50
|
+
|
51
|
+
You can use the API of rspec2minitest to easily create your own integrations
|
52
|
+
within your test_helper. `require 'rspec2minitest'` provides you with an
|
53
|
+
RSpec2MiniTest module that provides an `add_matcher` function to convert
|
54
|
+
single matchers and an `add_matchers` function to convert all public instance
|
55
|
+
methods of a given module.
|
33
56
|
|
34
|
-
|
35
|
-
|
36
|
-
|
57
|
+
Have a look at the integrations in `lib/rspec2minitest` for examples and do
|
58
|
+
not forget to issue a pull request to add `lib/rspec2minitest/#{gemname}.rb`
|
59
|
+
to the rspec2minitest spec. :)
|
data/lib/rspec2minitest.rb
CHANGED
@@ -4,14 +4,25 @@ module RSpec2MiniTest
|
|
4
4
|
module_function
|
5
5
|
|
6
6
|
def add_matcher(matcher_name, matcher_module: nil, assertion_prefix: nil)
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
7
|
+
test_names = [
|
8
|
+
RSpec2MiniTest::PositiveTestName,
|
9
|
+
RSpec2MiniTest::NegativeTestName
|
10
|
+
]
|
11
|
+
|
12
|
+
test_names.each do |test_name|
|
13
|
+
define_expectation(
|
14
|
+
test_name.new(matcher_name, matcher_module, assertion_prefix)
|
15
|
+
)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
module_function
|
20
|
+
|
21
|
+
def add_matchers(matcher_module, assertion_prefix: nil)
|
22
|
+
matcher_module.public_instance_methods.each do |matcher_name|
|
23
|
+
add_matcher matcher_name,
|
24
|
+
matcher_module: matcher_module,
|
25
|
+
assertion_prefix: assertion_prefix
|
15
26
|
end
|
16
27
|
end
|
17
28
|
|
@@ -22,10 +33,10 @@ module RSpec2MiniTest
|
|
22
33
|
|
23
34
|
def define_assertion(test_name)
|
24
35
|
method_name = test_name.assertion_name
|
25
|
-
MiniTest::Assertions.send(:define_method, method_name) do |
|
36
|
+
MiniTest::Assertions.send(:define_method, method_name) do |object, *args|
|
26
37
|
matcher = test_name.matcher(*args)
|
27
38
|
|
28
|
-
matches = matcher.send test_name.match_method,
|
39
|
+
matches = matcher.send test_name.match_method, object
|
29
40
|
failure_message = message { matcher.send test_name.failure_message_method }
|
30
41
|
|
31
42
|
assert matches, failure_message
|
@@ -1,10 +1,12 @@
|
|
1
|
+
require 'verbs'
|
2
|
+
|
1
3
|
module RSpec2MiniTest
|
2
4
|
class TestName
|
3
|
-
def initialize(matcher_name, matcher_module
|
5
|
+
def initialize(matcher_name, matcher_module, assertion_prefix)
|
4
6
|
extend matcher_module if matcher_module
|
5
7
|
|
6
8
|
@matcher_name = matcher_name.to_s
|
7
|
-
@assertion_prefix = assertion_prefix
|
9
|
+
@assertion_prefix = assertion_prefix && "#{assertion_prefix}_" || ''
|
8
10
|
end
|
9
11
|
|
10
12
|
def matcher(*args)
|
@@ -13,14 +15,16 @@ module RSpec2MiniTest
|
|
13
15
|
|
14
16
|
private
|
15
17
|
|
16
|
-
def
|
17
|
-
@matcher_name.
|
18
|
+
def conjugated
|
19
|
+
pieces = @matcher_name.split('_', 2)
|
20
|
+
pieces[0] = pieces[0].verb.conjugate(person: :third)
|
21
|
+
pieces.join('_')
|
18
22
|
end
|
19
23
|
end
|
20
24
|
|
21
25
|
class PositiveTestName < TestName
|
22
26
|
def assertion_name
|
23
|
-
"assert_#{@assertion_prefix
|
27
|
+
"assert_#{@assertion_prefix}_#{conjugated}"
|
24
28
|
end
|
25
29
|
|
26
30
|
def expectation_name
|
@@ -38,7 +42,7 @@ module RSpec2MiniTest
|
|
38
42
|
|
39
43
|
class NegativeTestName < TestName
|
40
44
|
def assertion_name
|
41
|
-
"refute_#{@assertion_prefix
|
45
|
+
"refute_#{@assertion_prefix}#{conjugated}"
|
42
46
|
end
|
43
47
|
|
44
48
|
def expectation_name
|
data/rspec2minitest.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec2minitest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christopher Schramm
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11-
|
11
|
+
date: 2013-11-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -28,16 +28,30 @@ dependencies:
|
|
28
28
|
name: minitest
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 2.0.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.0.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: verbs
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
39
46
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
description: |2
|
42
56
|
|
43
57
|
Provides a generic factory to automatically convert RSpec matchers
|
@@ -49,10 +63,13 @@ extra_rdoc_files:
|
|
49
63
|
- README.md
|
50
64
|
files:
|
51
65
|
- .gitignore
|
66
|
+
- CHANGELOG.md
|
52
67
|
- Gemfile
|
53
68
|
- LICENSE
|
54
69
|
- README.md
|
55
70
|
- lib/rspec2minitest.rb
|
71
|
+
- lib/rspec2minitest/capybara.rb
|
72
|
+
- lib/rspec2minitest/paperclip.rb
|
56
73
|
- lib/rspec2minitest/test_name.rb
|
57
74
|
- lib/rspec2minitest/version.rb
|
58
75
|
- rspec2minitest.gemspec
|
@@ -76,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
93
|
version: '0'
|
77
94
|
requirements: []
|
78
95
|
rubyforge_project:
|
79
|
-
rubygems_version: 2.
|
96
|
+
rubygems_version: 2.1.2
|
80
97
|
signing_key:
|
81
98
|
specification_version: 4
|
82
99
|
summary: Provides a generic factory to automatically convert RSpec matchers into assertions
|