simple_assertions 0.4.1 → 0.6.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 +7 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +18 -0
- data/.rubocop_todo.yml +29 -0
- data/.travis.yml +23 -4
- data/Gemfile +8 -0
- data/README.md +54 -0
- data/Rakefile +16 -5
- data/lib/simple_assertions.rb +4 -4
- data/lib/simple_assertions/assert_errors_on.rb +23 -17
- data/lib/simple_assertions/assert_raises.rb +2 -2
- data/lib/simple_assertions/version.rb +1 -1
- data/rakelib/rubocop.rake +18 -0
- data/simple_assertions.gemspec +9 -6
- data/test/helper.rb +10 -9
- data/test/simple_assertions/assert_errors_on_test.rb +150 -0
- data/test/{simple_assertions_assert_raises_test.rb → simple_assertions/assert_raises_test.rb} +14 -14
- data/test/simple_assertions_test.rb +1 -1
- metadata +66 -29
- data/.rvmrc +0 -1
- data/README.rdoc +0 -44
- data/lib/simple_assertions/minitest.rb +0 -3
- data/lib/simple_assertions/testunit.rb +0 -3
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ab353a3f99dec499be827540ec3214f657402b4f
|
4
|
+
data.tar.gz: f75755baa2a76e2d3a81fc726a0b6d3640fafe8a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: aeffe28c5440cb24cb803bad688685678f3878defd60f9db0e9f75c0acfdcbbe9e976f54d62d59ab07abac2f8f6c368a3ce7efde0341db1a5974ec54c2e2f113
|
7
|
+
data.tar.gz: ef4b1baa4fb63e0ef739253faa72b8cd9995bc19410268e35f344d91f3005e6b9675af179b48b858634794dc7eee223e7275c49eda2cf21e11e3d87a7a48c1d5
|
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# Generated by `rubocop --auto-gen-config`
|
2
|
+
inherit_from: .rubocop_todo.yml
|
3
|
+
|
4
|
+
Lint/HandleExceptions:
|
5
|
+
Exclude:
|
6
|
+
- rakelib/*.rake
|
7
|
+
|
8
|
+
Style/Documentation:
|
9
|
+
Enabled: false
|
10
|
+
|
11
|
+
Style/StringLiterals:
|
12
|
+
EnforcedStyle: double_quotes
|
13
|
+
|
14
|
+
Style/RegexpLiteral:
|
15
|
+
Enabled: false
|
16
|
+
|
17
|
+
Style/CaseEquality:
|
18
|
+
Enabled: false
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# This configuration was generated by `rubocop --auto-gen-config`
|
2
|
+
# on 2015-03-19 16:23:55 +0100 using RuboCop version 0.29.1.
|
3
|
+
# The point is for the user to remove these configuration records
|
4
|
+
# one by one as the offenses are removed from the code base.
|
5
|
+
# Note that changes in the inspected code, or installation of new
|
6
|
+
# versions of RuboCop, may require this file to be generated again.
|
7
|
+
|
8
|
+
# Offense count: 1
|
9
|
+
Metrics/AbcSize:
|
10
|
+
Max: 44
|
11
|
+
|
12
|
+
# Offense count: 1
|
13
|
+
# Configuration parameters: CountComments.
|
14
|
+
Metrics/ClassLength:
|
15
|
+
Max: 120
|
16
|
+
|
17
|
+
# Offense count: 1
|
18
|
+
Metrics/CyclomaticComplexity:
|
19
|
+
Max: 8
|
20
|
+
|
21
|
+
# Offense count: 15
|
22
|
+
# Configuration parameters: AllowURI, URISchemes.
|
23
|
+
Metrics/LineLength:
|
24
|
+
Max: 126
|
25
|
+
|
26
|
+
# Offense count: 1
|
27
|
+
# Configuration parameters: CountComments.
|
28
|
+
Metrics/MethodLength:
|
29
|
+
Max: 32
|
data/.travis.yml
CHANGED
@@ -1,6 +1,25 @@
|
|
1
1
|
language: ruby
|
2
|
+
sudo: false
|
3
|
+
cache: bundler
|
4
|
+
bundler_args: --without tools
|
2
5
|
rvm:
|
3
|
-
-
|
4
|
-
- 1
|
5
|
-
-
|
6
|
-
-
|
6
|
+
- 2.0
|
7
|
+
- 2.1
|
8
|
+
- 2.2
|
9
|
+
- ruby-head
|
10
|
+
- jruby-head
|
11
|
+
env:
|
12
|
+
global:
|
13
|
+
- CODECLIMATE_REPO_TOKEN=1b43f2bc46bf75b5ae0a4e0c956990346599bf84178fabec28f35c899947093b
|
14
|
+
- JRUBY_OPTS='--dev -J-Xmx1024M'
|
15
|
+
matrix:
|
16
|
+
fast_finish: true
|
17
|
+
allow_failures:
|
18
|
+
- rvm: jruby-head
|
19
|
+
notifications:
|
20
|
+
webhooks:
|
21
|
+
urls:
|
22
|
+
- https://webhooks.gitter.im/e/c6efc69df9417bda7808
|
23
|
+
on_success: change # options: [always|never|change] default: always
|
24
|
+
on_failure: always # options: [always|never|change] default: always
|
25
|
+
on_start: false # default: false
|
data/Gemfile
CHANGED
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
[github]: https://github.com/neopoly/simple_assertions
|
2
|
+
[doc]: http://rubydoc.info/github/neopoly/simple_assertions/master/file/README.md
|
3
|
+
[gem]: https://rubygems.org/gems/simple_assertions
|
4
|
+
[gem-badge]: https://img.shields.io/gem/v/simple_assertions.svg
|
5
|
+
[travis]: https://travis-ci.org/neopoly/simple_assertions
|
6
|
+
[travis-badge]: https://img.shields.io/travis/neopoly/simple_assertions.svg?branch=master
|
7
|
+
[codeclimate]: https://codeclimate.com/github/neopoly/simple_assertions
|
8
|
+
[codeclimate-climate-badge]: https://img.shields.io/codeclimate/github/neopoly/simple_assertions.svg
|
9
|
+
[codeclimate-coverage-badge]: https://codeclimate.com/github/neopoly/simple_assertions/badges/coverage.svg
|
10
|
+
[inchpages]: https://inch-ci.org/github/neopoly/simple_assertions
|
11
|
+
[inchpages-badge]: https://inch-ci.org/github/neopoly/simple_assertions.svg?branch=master&style=flat
|
12
|
+
|
13
|
+
# Simple assertions
|
14
|
+
|
15
|
+
[![Travis][travis-badge]][travis]
|
16
|
+
[![Gem Version][gem-badge]][gem]
|
17
|
+
[![Code Climate][codeclimate-climate-badge]][codeclimate]
|
18
|
+
[![Test Coverage][codeclimate-coverage-badge]][codeclimate]
|
19
|
+
[![Inline docs][inchpages-badge]][inchpages]
|
20
|
+
|
21
|
+
[Gem][gem] |
|
22
|
+
[Source][github] |
|
23
|
+
[Documentation][doc]
|
24
|
+
|
25
|
+
A collection of useful assertions.
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
require 'simple_assertions'
|
31
|
+
|
32
|
+
class MiniTest::TestCase
|
33
|
+
# include *SimpleAssertions.all
|
34
|
+
include SimpleAssertions::AssertErrorsOn
|
35
|
+
include SimpleAssertions::AssertRaises
|
36
|
+
end
|
37
|
+
```
|
38
|
+
|
39
|
+
## Assertions
|
40
|
+
|
41
|
+
* SimpleAssertions::AssertErrorsOn
|
42
|
+
* SimpleAssertions::AssertRaises
|
43
|
+
|
44
|
+
## Only >= 2.0 suported!
|
45
|
+
|
46
|
+
Note that only ruby version >= 2.0 is supported.
|
47
|
+
|
48
|
+
## Contributing
|
49
|
+
|
50
|
+
1. [Fork it](https://github.com/neopoly/simple_assertions/fork)
|
51
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
52
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
53
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
54
|
+
5. Create new Pull Request
|
data/Rakefile
CHANGED
@@ -1,12 +1,23 @@
|
|
1
|
+
require "bundler/setup"
|
1
2
|
require "bundler/gem_tasks"
|
2
3
|
|
3
4
|
# Test
|
4
|
-
require
|
5
|
-
desc
|
6
|
-
task :
|
5
|
+
require "rake/testtask"
|
6
|
+
desc "Default: run unit tests."
|
7
|
+
task default: :test
|
7
8
|
|
8
9
|
Rake::TestTask.new(:test) do |test|
|
9
|
-
test.test_files = FileList.new(
|
10
|
-
test.libs <<
|
10
|
+
test.test_files = FileList.new("test/**/*_test.rb")
|
11
|
+
test.libs << "test"
|
11
12
|
test.verbose = true
|
13
|
+
test.warning = true
|
14
|
+
end
|
15
|
+
|
16
|
+
# RDoc
|
17
|
+
require "rdoc/task"
|
18
|
+
RDoc::Task.new do |rdoc|
|
19
|
+
rdoc.title = "Simple assertions"
|
20
|
+
rdoc.rdoc_dir = "rdoc"
|
21
|
+
rdoc.main = "README.rdoc"
|
22
|
+
rdoc.rdoc_files.include("README.rdoc", "lib/**/*.rb")
|
12
23
|
end
|
data/lib/simple_assertions.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module SimpleAssertions
|
2
|
-
autoload :AssertErrorsOn,
|
3
|
-
autoload :AssertRaises,
|
2
|
+
autoload :AssertErrorsOn, "simple_assertions/assert_errors_on"
|
3
|
+
autoload :AssertRaises, "simple_assertions/assert_raises"
|
4
4
|
|
5
|
-
autoload :VERSION,
|
5
|
+
autoload :VERSION, "simple_assertions/version"
|
6
6
|
|
7
7
|
def self.all
|
8
|
-
mods = constants - [
|
8
|
+
mods = constants - [:VERSION]
|
9
9
|
mods.map { |mod| const_get(mod) }
|
10
10
|
end
|
11
11
|
end
|
@@ -1,23 +1,25 @@
|
|
1
1
|
module SimpleAssertions
|
2
2
|
module AssertErrorsOn
|
3
|
-
# http://gist.github.com/49013
|
4
|
-
#
|
5
3
|
# Assert errors on given parameters.
|
6
|
-
# It
|
4
|
+
# It calls #valid? on +object+ unless called with a block.
|
7
5
|
#
|
8
6
|
# == Example
|
9
7
|
#
|
10
8
|
# assert_errors_on record, :email
|
11
9
|
# assert_errors_on record, :email => 2
|
12
|
-
# assert_errors_on record, :email => "
|
10
|
+
# assert_errors_on record, :email => "can't be blank"
|
11
|
+
# assert_errors_on record, :email => :"errors.messages.blank"
|
12
|
+
# assert_errors_on record, :email => :"errors.attributes.email.blank"
|
13
13
|
# assert_errors_on record, :email => /blank/
|
14
|
-
# assert_errors_on record, :email => ["
|
14
|
+
# assert_errors_on record, :email => ["can't be blank", "is invalid"]
|
15
15
|
# assert_errors_on record, :email, :plz => 2
|
16
|
-
# assert_errors_on record, [:username, :email] => "
|
16
|
+
# assert_errors_on record, [:username, :email] => "can't be blank"
|
17
17
|
#
|
18
18
|
# assert_errors_on record, :email => 1 do
|
19
|
-
# assert record.save
|
19
|
+
# assert !record.save
|
20
20
|
# end
|
21
|
+
#
|
22
|
+
# Based on http://gist.github.com/49013
|
21
23
|
def assert_errors_on(object, *attributes_or_hash)
|
22
24
|
if block_given?
|
23
25
|
yield
|
@@ -25,28 +27,32 @@ module SimpleAssertions
|
|
25
27
|
assert !object.valid?, "#{object.inspect} should be invalid."
|
26
28
|
end
|
27
29
|
|
28
|
-
hash = attributes_or_hash
|
29
|
-
attributes_or_hash.each { |field| hash[field]
|
30
|
+
hash = attributes_or_hash.last.is_a?(Hash) ? attributes_or_hash.pop : {}
|
31
|
+
attributes_or_hash.each { |field| hash[field] ||= 1 }
|
30
32
|
|
31
33
|
hash.each do |fields, pattern|
|
32
|
-
Array
|
33
|
-
errors = Array
|
34
|
+
Array(fields).each do |field|
|
35
|
+
errors = Array(object.errors[field])
|
34
36
|
|
35
37
|
case pattern
|
36
38
|
when Fixnum
|
37
39
|
assert_equal pattern, errors.size,
|
38
|
-
|
40
|
+
"#{pattern} error(s) expected for #{object.class}.#{field} but got #{errors.inspect}."
|
39
41
|
when Regexp
|
40
42
|
assert errors.all? { |message| pattern.match(message) },
|
41
|
-
|
43
|
+
"expected to match #{pattern} for #{object.class}.#{field} but got #{errors.inspect}."
|
42
44
|
when String
|
43
|
-
assert_equal [
|
44
|
-
|
45
|
+
assert_equal [pattern], errors,
|
46
|
+
"#{pattern.inspect} expected for #{object.class}.#{field} but got #{errors.inspect}."
|
47
|
+
when Symbol
|
48
|
+
translation = I18n.t(pattern)
|
49
|
+
assert_equal [translation], errors,
|
50
|
+
"#{pattern.inspect}(#{translation}) expected for #{object.class}.#{field} but got #{errors.inspect}."
|
45
51
|
when Array
|
46
52
|
assert_equal pattern.sort, errors.sort,
|
47
|
-
|
53
|
+
"#{pattern.inspect} expected for #{object.class}.#{field} but got #{errors.inspect}."
|
48
54
|
else
|
49
|
-
|
55
|
+
flunk "unknown matcher type #{pattern.class}: #{pattern.inspect}"
|
50
56
|
end
|
51
57
|
end
|
52
58
|
end
|
@@ -18,11 +18,11 @@ module SimpleAssertions
|
|
18
18
|
module AssertRaises
|
19
19
|
def assert_raises(*args, &block)
|
20
20
|
attributes = args.last.is_a?(Hash) ? args.pop : {}
|
21
|
-
|
21
|
+
super(*args, &block).tap do |exception|
|
22
22
|
attributes.each do |attribute, expected|
|
23
23
|
assert_respond_to exception, attribute
|
24
24
|
actual = exception.public_send(attribute)
|
25
|
-
msg = "Expected #{mu_pp(expected)} to match #{mu_pp(actual)} for #{attribute} on #{mu_pp(exception)}"
|
25
|
+
msg = proc { "Expected #{mu_pp(expected)} to match #{mu_pp(actual)} for #{attribute} on #{mu_pp(exception)}" }
|
26
26
|
matched = expected == actual || expected === actual
|
27
27
|
assert matched, msg
|
28
28
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
begin
|
2
|
+
require "rubocop/rake_task"
|
3
|
+
|
4
|
+
Rake::Task[:default].enhance [:rubocop]
|
5
|
+
|
6
|
+
RuboCop::RakeTask.new do |task|
|
7
|
+
task.options << "--display-cop-names"
|
8
|
+
end
|
9
|
+
|
10
|
+
namespace :rubocop do
|
11
|
+
desc "Generate a configuration file acting as a TODO list."
|
12
|
+
task :auto_gen_config do
|
13
|
+
exec "bundle exec rubocop --auto-gen-config"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
rescue LoadError
|
18
|
+
end
|
data/simple_assertions.gemspec
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
|
2
|
+
$LOAD_PATH.push File.expand_path("../lib", __FILE__)
|
3
3
|
require "simple_assertions"
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
@@ -8,17 +8,20 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.authors = ["Peter Suschlik"]
|
9
9
|
s.email = ["ps@neopoly.de"]
|
10
10
|
s.homepage = "https://github.com/neopoly/simple_assertions"
|
11
|
-
s.summary =
|
12
|
-
s.description =
|
11
|
+
s.summary = "A collection of useful assertions."
|
12
|
+
s.description = s.summary
|
13
13
|
|
14
|
-
s.required_ruby_version =
|
14
|
+
s.required_ruby_version = ">= 2.0"
|
15
15
|
|
16
16
|
s.files = `git ls-files`.split("\n")
|
17
17
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
|
21
21
|
s.add_runtime_dependency "rake"
|
22
|
+
s.add_runtime_dependency "rdoc"
|
22
23
|
|
23
|
-
s.add_development_dependency "minitest", "
|
24
|
+
s.add_development_dependency "minitest", "~> 5.5.1"
|
25
|
+
s.add_development_dependency "testem"
|
26
|
+
s.add_development_dependency "activemodel"
|
24
27
|
end
|
data/test/helper.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
1
|
-
require
|
1
|
+
require "bundler/setup"
|
2
2
|
|
3
|
-
|
4
|
-
require
|
3
|
+
if ENV["CODECLIMATE_REPO_TOKEN"]
|
4
|
+
require "codeclimate-test-reporter"
|
5
|
+
CodeClimate::TestReporter.start
|
6
|
+
end
|
7
|
+
|
8
|
+
require "minitest/autorun"
|
9
|
+
require "testem"
|
5
10
|
|
6
|
-
require
|
11
|
+
require "simple_assertions"
|
7
12
|
|
8
|
-
class Spec <
|
9
|
-
class << self
|
10
|
-
alias :context :describe
|
11
|
-
alias :test :it
|
12
|
-
end
|
13
|
+
class Spec < Testem
|
13
14
|
end
|
@@ -0,0 +1,150 @@
|
|
1
|
+
require "helper"
|
2
|
+
|
3
|
+
require "active_model"
|
4
|
+
|
5
|
+
class SimpleAssertionsAssertErrorsOnTest < Spec
|
6
|
+
include SimpleAssertions::AssertRaises
|
7
|
+
include SimpleAssertions::AssertErrorsOn
|
8
|
+
|
9
|
+
Person = Struct.new(:username, :email, :fullname) do
|
10
|
+
extend ActiveModel::Naming
|
11
|
+
include ActiveModel::Validations
|
12
|
+
|
13
|
+
validates :username, presence: true
|
14
|
+
validates :email, presence: true, format: { with: %r{\A.+?@.*\z}, allow_blank: true }
|
15
|
+
validates :fullname, presence: true, format: /\A\S+ \S+\z/
|
16
|
+
|
17
|
+
def persisted?
|
18
|
+
false
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "setup" do
|
23
|
+
test "factories" do
|
24
|
+
assert valid.valid?
|
25
|
+
refute empty.valid?
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "basic" do
|
30
|
+
test "validate record" do
|
31
|
+
assert_assertion(/should be invalid/) do
|
32
|
+
assert_errors_on valid
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
test "yield block" do
|
37
|
+
assert_assertion "inside" do
|
38
|
+
assert_errors_on empty do
|
39
|
+
flunk "inside"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context "error count with fixnum" do
|
46
|
+
test "correct" do
|
47
|
+
assert_errors_on empty, username: 1, email: 1
|
48
|
+
assert_errors_on empty, username: 1
|
49
|
+
assert_errors_on empty, [:username, :email] => 1
|
50
|
+
assert_errors_on valid, username: 0, email: 0, fullname: 0 do
|
51
|
+
assert valid.valid?
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
test "implicit count is 1" do
|
56
|
+
assert_errors_on empty, :username, :email
|
57
|
+
end
|
58
|
+
|
59
|
+
test "does not overwrite with implicit count" do
|
60
|
+
assert_errors_on empty, :fullname, fullname: 2
|
61
|
+
end
|
62
|
+
|
63
|
+
test "fail" do
|
64
|
+
assert_assertion(/2 error\(s\) expected for .*?\.username/) do
|
65
|
+
assert_errors_on empty, username: 2
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context "partial match with regexp" do
|
71
|
+
test "match" do
|
72
|
+
assert_errors_on empty, username: /blank/, email: /blank/
|
73
|
+
assert_errors_on person(username: nil, email: "invalid"), username: /blank/, email: /invalid/
|
74
|
+
assert_errors_on empty, username: /blank/
|
75
|
+
assert_errors_on empty, [:username, :email] => /blank/
|
76
|
+
end
|
77
|
+
|
78
|
+
test "mismatch" do
|
79
|
+
assert_assertion(/expected to match.*?invalid.*?\.username/) do
|
80
|
+
assert_errors_on empty, username: /invalid/
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context "exact single string match" do
|
86
|
+
test "match" do
|
87
|
+
assert_errors_on empty, username: "can't be blank", email: "can't be blank"
|
88
|
+
assert_errors_on person(username: nil, email: "invalid"), username: "can't be blank", email: "is invalid"
|
89
|
+
assert_errors_on empty, [:username, :email] => "can't be blank"
|
90
|
+
end
|
91
|
+
|
92
|
+
test "mismatch" do
|
93
|
+
assert_assertion(/"is invalid" expected for.*?\.username/) do
|
94
|
+
assert_errors_on empty, username: "is invalid"
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
context "exact string match with array" do
|
100
|
+
test "match" do
|
101
|
+
assert_errors_on person(fullname: nil), fullname: ["can't be blank", "is invalid"]
|
102
|
+
assert_errors_on person(fullname: nil), fullname: ["is invalid", "can't be blank"]
|
103
|
+
end
|
104
|
+
|
105
|
+
test "mismatch" do
|
106
|
+
assert_assertion(/\["yay"\] expected for.*?\.fullname/) do
|
107
|
+
assert_errors_on person(fullname: nil), fullname: ["yay"]
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
context "translation match with symbol" do
|
113
|
+
test "match" do
|
114
|
+
assert_errors_on empty, username: :"errors.messages.blank"
|
115
|
+
end
|
116
|
+
|
117
|
+
test "mismatch" do
|
118
|
+
assert_assertion(/:"errors\.messages\.invalid\"\(is invalid\) expected for.*?\.username/) do
|
119
|
+
assert_errors_on empty, username: :"errors.messages.invalid"
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
context "unknown matcher type" do
|
125
|
+
test "fails" do
|
126
|
+
assert_assertion("unknown matcher type Float: 1.0") do
|
127
|
+
assert_errors_on empty, username: 1.0
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
private
|
133
|
+
|
134
|
+
def assert_assertion(msg, &block)
|
135
|
+
assert_raises(MiniTest::Assertion, message: msg, &block)
|
136
|
+
end
|
137
|
+
|
138
|
+
def empty
|
139
|
+
person(username: nil, email: nil, fullname: nil)
|
140
|
+
end
|
141
|
+
|
142
|
+
def valid
|
143
|
+
person
|
144
|
+
end
|
145
|
+
|
146
|
+
def person(attributes = {})
|
147
|
+
attributes = { username: "foo", email: "foo@bar.com", fullname: "Foo Bar" }.merge(attributes)
|
148
|
+
Person.new(*attributes.values_at(:username, :email, :fullname))
|
149
|
+
end
|
150
|
+
end
|
data/test/{simple_assertions_assert_raises_test.rb → simple_assertions/assert_raises_test.rb}
RENAMED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "helper"
|
2
2
|
|
3
3
|
class SimpleAssertionsAssertRaisesTest < Spec
|
4
4
|
class MyError < StandardError
|
@@ -20,58 +20,58 @@ class SimpleAssertionsAssertRaisesTest < Spec
|
|
20
20
|
protected :enemy
|
21
21
|
end
|
22
22
|
|
23
|
-
def my_error!(param=nil)
|
24
|
-
|
23
|
+
def my_error!(param = nil)
|
24
|
+
fail MyError, param
|
25
25
|
end
|
26
26
|
|
27
27
|
include SimpleAssertions::AssertRaises
|
28
28
|
|
29
29
|
context :assert_raises do
|
30
30
|
test "match param exactly" do
|
31
|
-
assert_raises MyError, :
|
31
|
+
assert_raises MyError, param: "string" do
|
32
32
|
my_error! "string"
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
36
|
test "match param via regexp" do
|
37
|
-
assert_raises MyError, :
|
37
|
+
assert_raises MyError, param: /string/i do
|
38
38
|
my_error! "my STRING rocks"
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
42
|
test "match param class" do
|
43
|
-
assert_raises MyError, :
|
43
|
+
assert_raises MyError, param: MyError do
|
44
44
|
my_error! MyError
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
48
|
test "param does not match on === operator" do
|
49
|
-
assert_raises MiniTest::Assertion, :
|
50
|
-
assert_raises MyError, :
|
49
|
+
assert_raises MiniTest::Assertion, message: /"foo" to match "bar"/ do
|
50
|
+
assert_raises MyError, param: "foo" do
|
51
51
|
my_error! "bar"
|
52
52
|
end
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
56
|
test "exception does not respond to invalid param" do
|
57
|
-
assert_raises MiniTest::Assertion, :
|
58
|
-
assert_raises MyError, :
|
57
|
+
assert_raises MiniTest::Assertion, message: /to respond to #invalid/ do
|
58
|
+
assert_raises MyError, invalid: "foo" do
|
59
59
|
my_error!
|
60
60
|
end
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
64
|
test "access to private exception param" do
|
65
|
-
assert_raises MiniTest::Assertion, :
|
66
|
-
assert_raises MyError, :
|
65
|
+
assert_raises MiniTest::Assertion, message: /to respond to #paula/ do
|
66
|
+
assert_raises MyError, paula: :sir do
|
67
67
|
my_error!
|
68
68
|
end
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
72
|
test "access to protected exception param" do
|
73
|
-
assert_raises
|
74
|
-
assert_raises MyError, :
|
73
|
+
assert_raises MiniTest::Assertion, message: /to respond to #enemy/ do
|
74
|
+
assert_raises MyError, enemy: :war do
|
75
75
|
my_error!
|
76
76
|
end
|
77
77
|
end
|
metadata
CHANGED
@@ -1,93 +1,130 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_assertions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.6.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Peter Suschlik
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2015-03-19 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rake
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rdoc
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
28
39
|
- !ruby/object:Gem::Version
|
29
40
|
version: '0'
|
30
41
|
- !ruby/object:Gem::Dependency
|
31
42
|
name: minitest
|
32
43
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
44
|
requirements:
|
35
|
-
- -
|
45
|
+
- - "~>"
|
36
46
|
- !ruby/object:Gem::Version
|
37
|
-
version:
|
47
|
+
version: 5.5.1
|
38
48
|
type: :development
|
39
49
|
prerelease: false
|
40
50
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
51
|
requirements:
|
43
|
-
- -
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 5.5.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: testem
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
44
60
|
- !ruby/object:Gem::Version
|
45
|
-
version: '
|
46
|
-
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: activemodel
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: A collection of useful assertions.
|
47
84
|
email:
|
48
85
|
- ps@neopoly.de
|
49
86
|
executables: []
|
50
87
|
extensions: []
|
51
88
|
extra_rdoc_files: []
|
52
89
|
files:
|
53
|
-
- .gitignore
|
54
|
-
- .
|
55
|
-
- .
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rubocop.yml"
|
92
|
+
- ".rubocop_todo.yml"
|
93
|
+
- ".travis.yml"
|
56
94
|
- Gemfile
|
57
|
-
- README.
|
95
|
+
- README.md
|
58
96
|
- Rakefile
|
59
97
|
- lib/simple_assertions.rb
|
60
98
|
- lib/simple_assertions/assert_errors_on.rb
|
61
99
|
- lib/simple_assertions/assert_raises.rb
|
62
|
-
- lib/simple_assertions/minitest.rb
|
63
|
-
- lib/simple_assertions/testunit.rb
|
64
100
|
- lib/simple_assertions/version.rb
|
101
|
+
- rakelib/rubocop.rake
|
65
102
|
- simple_assertions.gemspec
|
66
103
|
- test/helper.rb
|
67
|
-
- test/
|
104
|
+
- test/simple_assertions/assert_errors_on_test.rb
|
105
|
+
- test/simple_assertions/assert_raises_test.rb
|
68
106
|
- test/simple_assertions_test.rb
|
69
107
|
homepage: https://github.com/neopoly/simple_assertions
|
70
108
|
licenses: []
|
109
|
+
metadata: {}
|
71
110
|
post_install_message:
|
72
111
|
rdoc_options: []
|
73
112
|
require_paths:
|
74
113
|
- lib
|
75
114
|
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
-
none: false
|
77
115
|
requirements:
|
78
|
-
- -
|
116
|
+
- - ">="
|
79
117
|
- !ruby/object:Gem::Version
|
80
|
-
version:
|
118
|
+
version: '2.0'
|
81
119
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
-
none: false
|
83
120
|
requirements:
|
84
|
-
- -
|
121
|
+
- - ">="
|
85
122
|
- !ruby/object:Gem::Version
|
86
123
|
version: '0'
|
87
124
|
requirements: []
|
88
125
|
rubyforge_project:
|
89
|
-
rubygems_version:
|
126
|
+
rubygems_version: 2.2.2
|
90
127
|
signing_key:
|
91
|
-
specification_version:
|
92
|
-
summary:
|
128
|
+
specification_version: 4
|
129
|
+
summary: A collection of useful assertions.
|
93
130
|
test_files: []
|
data/.rvmrc
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
rvm @simple_assertions --create
|
data/README.rdoc
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
= Assertions for minitest or test/unit
|
2
|
-
|
3
|
-
A collection of usefull assertions.
|
4
|
-
|
5
|
-
Gem[https://rubygems.org/gems/simple_assertions] |
|
6
|
-
Source[https://github.com/neopoly/simple_assertions] |
|
7
|
-
RDoc[http://rubydoc.info/github/neopoly/simple_assertions/master/file/README.rdoc] |
|
8
|
-
{<img src="https://secure.travis-ci.org/neopoly/simple_assertions.png?branch=master" alt="Build Status" />}[http://travis-ci.org/neopoly/simple_assertions]
|
9
|
-
|
10
|
-
== Only >= 1.9.2 suported!
|
11
|
-
|
12
|
-
Note that only ruby version >= 1.9.2 is supported.
|
13
|
-
|
14
|
-
== Usage
|
15
|
-
|
16
|
-
=== minitest
|
17
|
-
|
18
|
-
To include all assertions for +minitest+ do:
|
19
|
-
|
20
|
-
require 'simple_assertions/minitest'
|
21
|
-
|
22
|
-
=== test/unit
|
23
|
-
|
24
|
-
To include all assertions for +test/unit+ do:
|
25
|
-
|
26
|
-
require 'simple_assertions/testunit'
|
27
|
-
|
28
|
-
=== manual
|
29
|
-
|
30
|
-
Or with more control what to include:
|
31
|
-
|
32
|
-
require 'simple_assertions'
|
33
|
-
|
34
|
-
class MiniTest::TestCase
|
35
|
-
# include *SimpleAssertions.all
|
36
|
-
include SimpleAssertions::AssertErrorsOn
|
37
|
-
include SimpleAssertions::AssertRaises
|
38
|
-
end
|
39
|
-
|
40
|
-
|
41
|
-
== Assertions
|
42
|
-
|
43
|
-
* assert_errors_on
|
44
|
-
* assert_raises
|