rspec2minitest 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e7593adead559b43c41faa38ad724b4f05c4c205
4
+ data.tar.gz: 2bd734b277cd890f2d29573278e2be409629644f
5
+ SHA512:
6
+ metadata.gz: e8a4ad5f694c808a2eb1f4160ebbe7483962e62b94ec71b800ca73df7aa7c34732de84ee639289f2369d844ed375b78b7fd3b763c7e17ea020bc556f6ff24d2c
7
+ data.tar.gz: 8d9ee06c36460d32ab62966252257e71f0a6120fea3fd06b55d0232432d5e5e7e544ca8c0c80d70978501d49565e5615a685931b8a7c96a87112e5eab728e52c
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ *.gem
2
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ Copyright (c) 2013 Christopher Schramm.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7
+ of the Software, and to permit persons to whom the Software is furnished to
8
+ do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
14
+ INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
15
+ PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
16
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
18
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # RSpec2MiniTest
2
+
3
+ Provides a generic factory to automatically convert the RSpec matchers of your favorite
4
+ gems into assertions and expectations for MiniTest::Unit and MiniTest::Spec.
5
+ It is a generalization of [Jared Ning's capybara_minitest_spec](https://github.com/ordinaryzelig/capybara_minitest_spec).
6
+
7
+ ## Installation
8
+
9
+ In your `Gemfile`:
10
+
11
+ gem 'rspec2minitest'
12
+
13
+ ## Examples
14
+
15
+ ### Capybara
16
+
17
+ To create assertions / expectations from all Capybara RSpec matchers add to your `test_helper`:
18
+
19
+ require 'rspec2minitest'
20
+ require 'capybara/rspec/matchers'
21
+ Capybara::RSpecMatchers.public_instance_methods.each do |matcher_name|
22
+ RSpec2MiniTest.add_matcher matcher_name,
23
+ matcher_module: Capybara::RSpecMatchers,
24
+ assertion_prefix: 'page'
25
+ end
26
+
27
+ This is exactly what the `capybara_minitest_spec` gem does. If Capybara
28
+ matchers are the only ones you need to convert, I recommend using that gem.
29
+
30
+ ### Paperclip
31
+
32
+ To create attachment assertions / expectations for your models add to your `test_helper`:
33
+
34
+ require 'rspec2minitest'
35
+ require 'paperclip/matchers'
36
+ RSpec2MiniTest.add_matcher 'have_attached_file', matcher_module: Paperclip::Shoulda::Matchers
@@ -0,0 +1,38 @@
1
+ require 'rspec2minitest/test_name'
2
+
3
+ module RSpec2MiniTest
4
+ module_function
5
+
6
+ def add_matcher(matcher_name, matcher_module: nil, assertion_prefix: nil)
7
+ positive_name = RSpec2MiniTest::PositiveTestName.new(
8
+ matcher_name, matcher_module: matcher_module, assertion_prefix: assertion_prefix
9
+ )
10
+ negative_name = RSpec2MiniTest::NegativeTestName.new(
11
+ matcher_name, matcher_module: matcher_module, assertion_prefix: assertion_prefix
12
+ )
13
+ [positive_name, negative_name].each do |test_name|
14
+ define_expectation test_name
15
+ end
16
+ end
17
+
18
+ def define_expectation(test_name)
19
+ define_assertion test_name
20
+ infect_assertion test_name
21
+ end
22
+
23
+ def define_assertion(test_name)
24
+ method_name = test_name.assertion_name
25
+ MiniTest::Assertions.send(:define_method, method_name) do |page, *args|
26
+ matcher = test_name.matcher(*args)
27
+
28
+ matches = matcher.send test_name.match_method, page
29
+ failure_message = message { matcher.send test_name.failure_message_method }
30
+
31
+ assert matches, failure_message
32
+ end
33
+ end
34
+
35
+ def infect_assertion(test_name)
36
+ MiniTest::Expectations.infect_an_assertion test_name.assertion_name, test_name.expectation_name, true
37
+ end
38
+ end
@@ -0,0 +1,56 @@
1
+ module RSpec2MiniTest
2
+ class TestName
3
+ def initialize(matcher_name, matcher_module: nil, assertion_prefix: nil)
4
+ extend matcher_module if matcher_module
5
+
6
+ @matcher_name = matcher_name.to_s
7
+ @assertion_prefix = assertion_prefix
8
+ end
9
+
10
+ def matcher(*args)
11
+ send @matcher_name, *args
12
+ end
13
+
14
+ private
15
+
16
+ def has
17
+ @matcher_name.sub /^have/, 'has'
18
+ end
19
+ end
20
+
21
+ class PositiveTestName < TestName
22
+ def assertion_name
23
+ "assert_#{@assertion_prefix && "#{@assertion_prefix}_" || ''}#{has}"
24
+ end
25
+
26
+ def expectation_name
27
+ "must_#{@matcher_name}"
28
+ end
29
+
30
+ def match_method
31
+ :matches?
32
+ end
33
+
34
+ def failure_message_method
35
+ :failure_message_for_should
36
+ end
37
+ end
38
+
39
+ class NegativeTestName < TestName
40
+ def assertion_name
41
+ "refute_#{@assertion_prefix && "#{@assertion_prefix}_" || ''}#{has}"
42
+ end
43
+
44
+ def expectation_name
45
+ "wont_#{@matcher_name}"
46
+ end
47
+
48
+ def match_method
49
+ :does_not_match?
50
+ end
51
+
52
+ def failure_message_method
53
+ :failure_message_for_should_not
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,11 @@
1
+ module RSpec2MiniTest
2
+ class Version
3
+ MAJOR = 0
4
+ MINOR = 1
5
+ PATCH = 0
6
+
7
+ def self.to_s
8
+ "#{MAJOR}.#{MINOR}.#{PATCH}"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,32 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/rspec2minitest/version', __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'rspec2minitest'
6
+ s.version = RSpec2MiniTest::Version.to_s
7
+ s.platform = Gem::Platform::RUBY
8
+ s.author = 'Christopher Schramm'
9
+ s.email = 'rspec2minitest@cschramm.eu'
10
+ s.homepage = 'https://github.com/cschramm/rspec2minitest'
11
+ s.description = %q{
12
+ Provides a generic factory to automatically convert RSpec matchers
13
+ into assertions and expections for MiniTest::Unit and MiniTest::Spec
14
+ }
15
+ s.summary = %q{
16
+ Provides a generic factory to automatically convert RSpec matchers
17
+ into assertions and expections for MiniTest::Unit and MiniTest::Spec.
18
+ It is a generalization of Jared Ning's capybara_minitest_spec.
19
+ }
20
+ s.licenses = %w(MIT)
21
+ s.files = `git ls-files`.split("\n")
22
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
23
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
24
+ s.require_paths = %w(lib)
25
+ s.extra_rdoc_files = %w(README.md)
26
+
27
+ s.required_ruby_version = '>= 2.0.0'
28
+
29
+ s.add_development_dependency 'rake'
30
+
31
+ s.add_runtime_dependency 'minitest', '~> 4.7'
32
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec2minitest
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Christopher Schramm
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '4.7'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '4.7'
41
+ description: |2
42
+
43
+ Provides a generic factory to automatically convert RSpec matchers
44
+ into assertions and expections for MiniTest::Unit and MiniTest::Spec
45
+ email: rspec2minitest@cschramm.eu
46
+ executables: []
47
+ extensions: []
48
+ extra_rdoc_files:
49
+ - README.md
50
+ files:
51
+ - .gitignore
52
+ - Gemfile
53
+ - LICENSE
54
+ - README.md
55
+ - lib/rspec2minitest.rb
56
+ - lib/rspec2minitest/test_name.rb
57
+ - lib/rspec2minitest/version.rb
58
+ - rspec2minitest.gemspec
59
+ homepage: https://github.com/cschramm/rspec2minitest
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - '>='
70
+ - !ruby/object:Gem::Version
71
+ version: 2.0.0
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.0.7
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: Provides a generic factory to automatically convert RSpec matchers into assertions
83
+ and expections for MiniTest::Unit and MiniTest::Spec. It is a generalization of
84
+ Jared Ning's capybara_minitest_spec.
85
+ test_files: []