test_plus 0.1.1

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: 97e83f1e828a00c93d4a5fc4d8c01593e7850bc2
4
+ data.tar.gz: c64338bdb827d667e18bdc5c6b5afb6678f04618
5
+ SHA512:
6
+ metadata.gz: a9776dd84740c8e7408a5b95e664af12d5bbd9eac8a5b7de163ec9496a3c930420b0cb5c2913a0b40958a1faffa21c14d1227f22c705ec45f5b166ea321edf77
7
+ data.tar.gz: 4c2252b7a3cfec44a2b3ae4639a4dc7b1294ae85ff61c2685f09903c2c22059b03475cba3305a49b1598e9671da0b30d3a813cebb1dad02a0406d52ba4362f83
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org/'
2
+
3
+ group :development do
4
+ gem 'bundler'
5
+ gem 'jeweler'
6
+ gem 'test-unit'
7
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,64 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ addressable (2.4.0)
5
+ builder (3.2.3)
6
+ descendants_tracker (0.0.4)
7
+ thread_safe (~> 0.3, >= 0.3.1)
8
+ faraday (0.9.2)
9
+ multipart-post (>= 1.2, < 3)
10
+ git (1.3.0)
11
+ github_api (0.16.0)
12
+ addressable (~> 2.4.0)
13
+ descendants_tracker (~> 0.0.4)
14
+ faraday (~> 0.8, < 0.10)
15
+ hashie (>= 3.4)
16
+ mime-types (>= 1.16, < 3.0)
17
+ oauth2 (~> 1.0)
18
+ hashie (3.5.6)
19
+ highline (1.7.8)
20
+ jeweler (2.3.7)
21
+ builder
22
+ bundler (>= 1)
23
+ git (>= 1.2.5)
24
+ github_api (~> 0.16.0)
25
+ highline (>= 1.6.15)
26
+ nokogiri (>= 1.5.10)
27
+ psych (~> 2.2)
28
+ rake
29
+ rdoc
30
+ semver2
31
+ jwt (1.5.6)
32
+ mime-types (2.99.3)
33
+ mini_portile2 (2.3.0)
34
+ multi_json (1.12.2)
35
+ multi_xml (0.6.0)
36
+ multipart-post (2.0.0)
37
+ nokogiri (1.8.1)
38
+ mini_portile2 (~> 2.3.0)
39
+ oauth2 (1.4.0)
40
+ faraday (>= 0.8, < 0.13)
41
+ jwt (~> 1.0)
42
+ multi_json (~> 1.3)
43
+ multi_xml (~> 0.5)
44
+ rack (>= 1.2, < 3)
45
+ power_assert (1.1.1)
46
+ psych (2.2.4)
47
+ rack (2.0.3)
48
+ rake (12.2.1)
49
+ rdoc (5.1.0)
50
+ semver2 (3.4.2)
51
+ test-unit (3.2.6)
52
+ power_assert
53
+ thread_safe (0.3.6)
54
+
55
+ PLATFORMS
56
+ ruby
57
+
58
+ DEPENDENCIES
59
+ bundler
60
+ jeweler
61
+ test-unit
62
+
63
+ BUNDLED WITH
64
+ 1.16.0
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2017 Scott Tadman
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,23 @@
1
+ # Test Plus
2
+
3
+ Helper extensions for testing Ruby and Rails code using Test::Unit and
4
+ MiniTest.
5
+
6
+ ## Usage
7
+
8
+ The `TestPlus` library can be imported into any project as necessary. Typically
9
+ this is done in the `test/helper.rb` file or equivalent:
10
+
11
+ class Test::Unit::TestCase
12
+ include TestPlus::Extensions
13
+ end
14
+
15
+ # Examples
16
+
17
+ The `test/` directory contains a number of examples demonstrating how the
18
+ various assertion rules are applied.
19
+
20
+ ## Copyright
21
+
22
+ Copyright (c) 2017 Scott Tadman. See LICENSE.txt for
23
+ further details.
data/Rakefile ADDED
@@ -0,0 +1,38 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+
6
+ begin
7
+ Bundler.setup(:default, :development, :test)
8
+ rescue Bundler::BundlerError => e
9
+ $stderr.puts e.message
10
+ $stderr.puts "Run `bundle install` to install missing gems"
11
+ exit e.status_code
12
+ end
13
+
14
+ require 'rake'
15
+ require 'jeweler'
16
+
17
+ Jeweler::Tasks.new do |gem|
18
+ # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
19
+ gem.name = "test_plus"
20
+ gem.homepage = "http://github.com/postageapp/test_plus"
21
+ gem.license = "MIT"
22
+ gem.summary = %Q{Extensions for Test::Unit and Minitest}
23
+ gem.description = %Q{Convenience methods for testing in Ruby and Rails}
24
+ gem.email = "tadman@postageapp.com"
25
+ gem.authors = ["Scott Tadman"]
26
+ # dependencies defined in Gemfile
27
+ end
28
+
29
+ Jeweler::RubygemsDotOrgTasks.new
30
+
31
+ require 'rake/testtask'
32
+ Rake::TestTask.new(:test) do |test|
33
+ test.libs << 'lib' << 'test'
34
+ test.pattern = 'test/**/test_*.rb'
35
+ test.verbose = true
36
+ end
37
+
38
+ task default: :test
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.1
@@ -0,0 +1,108 @@
1
+ module TestPlus::Extensions
2
+ # == Mixin Methods ========================================================
3
+
4
+ # Tests that a model was created properly: That no errors were reported,
5
+ # that the model is listed as valid, and that it's no longer flagged as a
6
+ # new record.
7
+ def assert_created(model)
8
+ assert(model, "Model was not defined")
9
+ assert_equal([ ], model.errors.full_messages)
10
+ assert(model.valid?, "Model failed to validate")
11
+ assert(!model.new_record?, "Model is still a new record")
12
+ end
13
+
14
+ # Tests that a model was not created by verifying that it has not been saved.
15
+ def assert_not_created(model)
16
+ assert(model, "Model was not defined")
17
+ assert(model.new_record?, "Model has been saved")
18
+ end
19
+ alias_method :refute_created, :assert_not_created
20
+
21
+ # Tests that the given model has errors on the specified attributes. Any
22
+ # additional errors will be reported as anomalous, and any missing ones
23
+ # will be flagged as well.
24
+ def assert_errors_on(model, *attrs)
25
+ found_attrs = [ ]
26
+
27
+ model.errors.each do |attr, error|
28
+ found_attrs << attr
29
+ end
30
+
31
+ assert_equal(
32
+ attrs.flatten.collect(&:to_s).sort,
33
+ found_attrs.uniq.collect(&:to_s).sort
34
+ )
35
+ end
36
+
37
+ # Tests that two lists of objects contain the same values when calling a
38
+ # method on the itens in question, if they respond to it. Those items that
39
+ # do not respond to the method are treated as-is.
40
+ def assert_equal_reduced(a, b, reduce, message = nil, &block)
41
+ assert_equal(
42
+ TestPlus::Support.reduce_with(a, reduce).to_a.sort,
43
+ TestPlus::Support.reduce_with(b, reduce).to_a.sort,
44
+ message,
45
+ &block
46
+ )
47
+ end
48
+
49
+ # Tests a number of cases simultaneously using a key-value Hash to map
50
+ # inputs to expected outputs. The keys are supplied to a block and the
51
+ # result of that block is compared to the expected value. Any mistakes
52
+ # are reported as failures.
53
+ def assert_mapping(map)
54
+ result_map = map.each_with_object({ }) do |(k,_), h|
55
+ if (k and k.respond_to?(:freeze))
56
+ k = k.freeze
57
+ end
58
+
59
+ h[k] = yield(k)
60
+ end
61
+
62
+ differences = result_map.each_with_object([ ]) do |(k,v), a|
63
+ next unless (v == map[k])
64
+
65
+ a << k
66
+ end
67
+
68
+ assert_equal(
69
+ map,
70
+ result_map,
71
+ differences.collect do |s|
72
+ "Input: #{s.inspect}\n Expected: #{map[s].inspect}\n Result: #{result_map[s].inspect}\n"
73
+ end.join('')
74
+ )
75
+ end
76
+
77
+ # Tests that an exceeption is raised. An optional exception class can be
78
+ # provided to ensure that the exception is of the correct type.
79
+ def assert_exception_raised(exception_class = nil, error_text = nil, message = nil, &block)
80
+ exception_raised = nil
81
+
82
+ yield
83
+
84
+ rescue Object => exception_raised
85
+ if (exception_class)
86
+ assert(
87
+ exception_raised.is_a?(exception_class),
88
+ message || "Exception raised is not of type #{exception_class}, instead is #{exception_raised.class}"
89
+ )
90
+ else
91
+ assert(true)
92
+ end
93
+
94
+ if (error_text)
95
+ assert_equal(
96
+ error_text,
97
+ exception_raised.to_s,
98
+ message || "Exception raised had incorrect text"
99
+ )
100
+ end
101
+ else
102
+ if (exception_class)
103
+ flunk(message || "Exception of type #{exception_class} was not raised")
104
+ else
105
+ flunk(message || "An exception was not raised")
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,17 @@
1
+ module TestPlus::Support
2
+ # == Module Methods =======================================================
3
+
4
+ def reduce_with(list, reduction)
5
+ case (reduction)
6
+ when Symbol
7
+ reduction_method = reduction
8
+ reduction = lambda do |o|
9
+ o.respond_to?(reduction_method) ? o.send(reduction_method) : o
10
+ end
11
+ end
12
+
13
+ list.to_a.flatten.map(&reduction)
14
+ end
15
+
16
+ extend self
17
+ end
data/lib/test_plus.rb ADDED
@@ -0,0 +1,5 @@
1
+ module TestPlus
2
+ end
3
+
4
+ require_relative './test_plus/extensions'
5
+ require_relative './test_plus/support'
data/test/helper.rb ADDED
@@ -0,0 +1,20 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development, :test)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+
11
+ require 'test/unit'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+
16
+ require 'test_plus'
17
+
18
+ class Test::Unit::TestCase
19
+ include TestPlus::Extensions
20
+ end
@@ -0,0 +1,28 @@
1
+ require_relative './helper'
2
+
3
+ class TestTestPlus < Test::Unit::TestCase
4
+ def test_assert_mapping
5
+ assert_mapping(
6
+ 'a' => 'A',
7
+ 'A' => 'A',
8
+ nil => nil
9
+ ) do |letter|
10
+ letter and letter.upcase
11
+ end
12
+ end
13
+
14
+ def test_assert_exception_raised
15
+ assert_exception_raised ArgumentError do
16
+ ''.to_s(1)
17
+ end
18
+ end
19
+
20
+ def test_assert_equal_reduced
21
+ a = [ 1, 2, 3, 4, 5 ]
22
+ b = %w[ 1 2 3 4 5 ]
23
+
24
+ assert_equal_reduced(a, b, :to_s)
25
+
26
+ assert_equal_reduced(a, b, ->(v) { v.to_s })
27
+ end
28
+ end
data/test_plus.gemspec ADDED
@@ -0,0 +1,58 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+ # stub: test_plus 0.1.1 ruby lib
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "test_plus".freeze
9
+ s.version = "0.1.1"
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib".freeze]
13
+ s.authors = ["Scott Tadman".freeze]
14
+ s.date = "2017-11-06"
15
+ s.description = "Convenience methods for testing in Ruby and Rails".freeze
16
+ s.email = "tadman@postageapp.com".freeze
17
+ s.extra_rdoc_files = [
18
+ "LICENSE.txt",
19
+ "README.md"
20
+ ]
21
+ s.files = [
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.md",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "lib/test_plus.rb",
29
+ "lib/test_plus/extensions.rb",
30
+ "lib/test_plus/support.rb",
31
+ "test/helper.rb",
32
+ "test/test_test_plus.rb",
33
+ "test_plus.gemspec"
34
+ ]
35
+ s.homepage = "http://github.com/postageapp/test_plus".freeze
36
+ s.licenses = ["MIT".freeze]
37
+ s.rubygems_version = "2.6.13".freeze
38
+ s.summary = "Extensions for Test::Unit and Minitest".freeze
39
+
40
+ if s.respond_to? :specification_version then
41
+ s.specification_version = 4
42
+
43
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
44
+ s.add_development_dependency(%q<bundler>.freeze, [">= 0"])
45
+ s.add_development_dependency(%q<jeweler>.freeze, [">= 0"])
46
+ s.add_development_dependency(%q<test-unit>.freeze, [">= 0"])
47
+ else
48
+ s.add_dependency(%q<bundler>.freeze, [">= 0"])
49
+ s.add_dependency(%q<jeweler>.freeze, [">= 0"])
50
+ s.add_dependency(%q<test-unit>.freeze, [">= 0"])
51
+ end
52
+ else
53
+ s.add_dependency(%q<bundler>.freeze, [">= 0"])
54
+ s.add_dependency(%q<jeweler>.freeze, [">= 0"])
55
+ s.add_dependency(%q<test-unit>.freeze, [">= 0"])
56
+ end
57
+ end
58
+
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: test_plus
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Scott Tadman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-11-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
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: jeweler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: test-unit
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Convenience methods for testing in Ruby and Rails
56
+ email: tadman@postageapp.com
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files:
60
+ - LICENSE.txt
61
+ - README.md
62
+ files:
63
+ - Gemfile
64
+ - Gemfile.lock
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - VERSION
69
+ - lib/test_plus.rb
70
+ - lib/test_plus/extensions.rb
71
+ - lib/test_plus/support.rb
72
+ - test/helper.rb
73
+ - test/test_test_plus.rb
74
+ - test_plus.gemspec
75
+ homepage: http://github.com/postageapp/test_plus
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.6.13
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Extensions for Test::Unit and Minitest
99
+ test_files: []