hermod 2.6.1 → 2.7.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 +4 -4
- data/.github/workflows/freeagent-gem.yml +58 -0
- data/.github/workflows/reviewdog.yml +13 -0
- data/.ruby-version +1 -1
- data/CHANGELOG.md +19 -3
- data/README.md +1 -0
- data/hermod.gemspec +5 -4
- data/lib/hermod/validators/attributes.rb +1 -1
- data/lib/hermod/version.rb +1 -1
- data/lib/hermod/xml_section_builder.rb +2 -1
- data/spec/hermod/validators/allowed_values_spec.rb +5 -5
- data/spec/hermod/validators/attributes_spec.rb +3 -3
- data/spec/hermod/validators/base_spec.rb +3 -3
- data/spec/hermod/validators/non_negative_spec.rb +5 -5
- data/spec/hermod/validators/non_zero_spec.rb +5 -5
- data/spec/hermod/validators/range_spec.rb +6 -6
- data/spec/hermod/validators/regular_expression_spec.rb +5 -5
- data/spec/hermod/validators/type_checker_spec.rb +9 -9
- data/spec/hermod/validators/value_presence_spec.rb +3 -3
- data/spec/hermod/validators/whole_units_spec.rb +4 -4
- data/spec/hermod/xml_section_builder/date_node_spec.rb +3 -3
- data/spec/hermod/xml_section_builder/datetime_node_spec.rb +3 -3
- data/spec/hermod/xml_section_builder/integer_node_spec.rb +3 -3
- data/spec/hermod/xml_section_builder/monetary_node_spec.rb +12 -12
- data/spec/hermod/xml_section_builder/parent_node_spec.rb +1 -1
- data/spec/hermod/xml_section_builder/string_node_spec.rb +17 -17
- data/spec/hermod/xml_section_builder/yes_no_node_spec.rb +2 -2
- data/spec/hermod/xml_section_builder/yes_node_spec.rb +2 -2
- data/spec/hermod/xml_section_spec.rb +18 -18
- data/spec/hermod_spec.rb +1 -1
- metadata +16 -20
- data/Jenkinsfile +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d661471576b43558cd71f9d1cdd5cc880f309c78b466ff282013691ea1f92f1f
|
4
|
+
data.tar.gz: 111b5510e339ce143736e5d12f29ab7085e17b816702db3b497fe086843b5108
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed2e552c55970afb070a10fd8066daba21217aca91a4116ca9f365a31c93f5a9033caf5d356d49e45506bbcb05125f88b1cc5d10540c282d52ba70bd5b654566
|
7
|
+
data.tar.gz: 614466df8d6f6c6ca31a306a680f99f04dc865e14bba6fd7bbb89b272850fe3816234d8861cf2b1b9e711215e63b8f78d1d98e73e02316473f1f1c80430bbb1a
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# Build, test and push gems to the FreeAgent registry.
|
2
|
+
# https://github.com/orgs/fac/packages?ecosystem=rubygems
|
3
|
+
# https://www.notion.so/freeagent/Internal-gems-5c8098501fcc48e4921be31aa9b4d495
|
4
|
+
name: FreeAgent Gem
|
5
|
+
on:
|
6
|
+
push:
|
7
|
+
branches: [master]
|
8
|
+
pull_request:
|
9
|
+
|
10
|
+
jobs:
|
11
|
+
# Install the bundle and run the gems test suite.
|
12
|
+
tests:
|
13
|
+
runs-on: ubuntu-latest
|
14
|
+
|
15
|
+
steps:
|
16
|
+
- uses: actions/checkout@v2
|
17
|
+
- uses: ruby/setup-ruby@v1 # .ruby-version
|
18
|
+
with:
|
19
|
+
bundler-cache: true # bundle install
|
20
|
+
|
21
|
+
- name: Test
|
22
|
+
run: bundle exec rake
|
23
|
+
|
24
|
+
# Builds that pass testing above, will trigger a build and push of the new
|
25
|
+
# gem version to the registry. If the version.rb has not been bumped since
|
26
|
+
# the last release, the push will no-op.
|
27
|
+
release:
|
28
|
+
needs: tests
|
29
|
+
runs-on: ubuntu-latest
|
30
|
+
|
31
|
+
steps:
|
32
|
+
- uses: fac/ruby-gem-setup-credentials-action@v2
|
33
|
+
with:
|
34
|
+
user: ""
|
35
|
+
key: rubygems
|
36
|
+
token: ${{ secrets.FAC_RUBYGEMS_KEY }}
|
37
|
+
|
38
|
+
# Build the gem package
|
39
|
+
- uses: actions/checkout@v2
|
40
|
+
- uses: ruby/setup-ruby@v1
|
41
|
+
with:
|
42
|
+
bundler-cache: true
|
43
|
+
- run: bundle exec rake build
|
44
|
+
|
45
|
+
# Release production gem version from default branch
|
46
|
+
- name: Release
|
47
|
+
if: github.ref == 'refs/heads/master'
|
48
|
+
uses: fac/ruby-gem-push-action@v2
|
49
|
+
with:
|
50
|
+
key: rubygems
|
51
|
+
|
52
|
+
# PR branch builds will release pre-release gems
|
53
|
+
- name: Pre-Release
|
54
|
+
if: github.ref != 'refs/heads/master'
|
55
|
+
uses: fac/ruby-gem-push-action@v2
|
56
|
+
with:
|
57
|
+
key: rubygems
|
58
|
+
pre-release: true
|
@@ -0,0 +1,13 @@
|
|
1
|
+
name: reviewdog
|
2
|
+
on: [pull_request]
|
3
|
+
jobs:
|
4
|
+
actionlint:
|
5
|
+
name: runner / actionlint
|
6
|
+
runs-on: ubuntu-latest
|
7
|
+
steps:
|
8
|
+
- uses: actions/checkout@v3
|
9
|
+
- name: actionlint
|
10
|
+
uses: reviewdog/action-actionlint@v1
|
11
|
+
with:
|
12
|
+
fail_on_error: true
|
13
|
+
reporter: github-pr-review
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
3.0.3
|
data/CHANGELOG.md
CHANGED
@@ -6,16 +6,32 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
7
|
|
8
8
|
## [Unreleased]
|
9
|
-
|
9
|
+
|
10
|
+
## [2.7.0] - 2022-05-25
|
11
|
+
### Fixed
|
12
|
+
- Added missing require in `Hermod::XmlSectionBuilder`
|
13
|
+
- Fixed deprecations in Minitest
|
14
|
+
|
15
|
+
### Removed
|
16
|
+
- Remove unused bad_attributes attr_reader on `Hermod::Validators::Attributes`
|
17
|
+
|
18
|
+
### Changed
|
19
|
+
- Updated development dependencies
|
20
|
+
|
21
|
+
## [2.6.2] - 2022-01-10
|
22
|
+
### Changed
|
23
|
+
- Remove the upper limit on the activesupport version
|
24
|
+
|
25
|
+
## [2.6.1] - 2020-10-22
|
10
26
|
## Added
|
11
27
|
- Changelog updates
|
12
28
|
|
13
|
-
##[2.6.0] - 2020-10-22
|
29
|
+
## [2.6.0] - 2020-10-22
|
14
30
|
## Added
|
15
31
|
- Update libxml-ruby to version ~> 3.2
|
16
32
|
- Update ruby-version to 2.7.1
|
17
33
|
|
18
|
-
##[2.5.3] - 2019-11-01
|
34
|
+
## [2.5.3] - 2019-11-01
|
19
35
|
### Added
|
20
36
|
- Link wiki to the readme file.
|
21
37
|
|
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# Hermod
|
2
2
|
|
3
|
+
[](https://github.com/fac/hermod/actions/workflows/freeagent-gem.yml)
|
3
4
|
[](https://codeclimate.com/github/fac/hermod)
|
5
6
|
[](https://travis-ci.org/fac/hermod)
|
data/hermod.gemspec
CHANGED
@@ -23,15 +23,16 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.required_ruby_version = ">= 2.0.0"
|
24
24
|
|
25
25
|
spec.add_runtime_dependency "libxml-ruby", "~> 3.2"
|
26
|
-
spec.add_runtime_dependency "activesupport", "> 3.2"
|
26
|
+
spec.add_runtime_dependency "activesupport", "> 3.2"
|
27
27
|
|
28
28
|
spec.add_development_dependency "bundler", "~> 2.0"
|
29
29
|
spec.add_development_dependency "rake", "13.0.1"
|
30
|
-
spec.add_development_dependency "minitest", "~> 5.
|
31
|
-
spec.add_development_dependency "minitest-reporters", "
|
32
|
-
spec.add_development_dependency "nokogiri", "~> 1.
|
30
|
+
spec.add_development_dependency "minitest", "~> 5.15"
|
31
|
+
spec.add_development_dependency "minitest-reporters", ">= 1.0.16", "~> 1.5"
|
32
|
+
spec.add_development_dependency "nokogiri", "~> 1.13"
|
33
33
|
|
34
34
|
spec.metadata = {
|
35
|
+
"allowed_push_host" => "https://rubygems.org",
|
35
36
|
"bug_tracker_uri" => "https://github.com/fac/hermod/issues",
|
36
37
|
"changelog_uri" => "https://github.com/fac/hermod/blob/master/CHANGELOG.md",
|
37
38
|
"source_code_uri" => "https://github.com/fac/hermod",
|
@@ -4,7 +4,7 @@ module Hermod
|
|
4
4
|
module Validators
|
5
5
|
# Checks the attributes are in a list of allowed attributes
|
6
6
|
class Attributes < Base
|
7
|
-
attr_reader :allowed_attributes
|
7
|
+
attr_reader :allowed_attributes
|
8
8
|
|
9
9
|
# Public: Sets up the list of allowed attributes
|
10
10
|
def initialize(allowed_attributes)
|
data/lib/hermod/version.rb
CHANGED
@@ -8,17 +8,17 @@ module Hermod
|
|
8
8
|
end
|
9
9
|
|
10
10
|
it "permits values in the list" do
|
11
|
-
subject.valid?("Cat", {}).must_equal true
|
11
|
+
expect(subject.valid?("Cat", {})).must_equal true
|
12
12
|
end
|
13
13
|
|
14
14
|
it "allows blank values" do
|
15
|
-
subject.valid?("", {}).must_equal true
|
16
|
-
subject.valid?(nil, {}).must_equal true
|
15
|
+
expect(subject.valid?("", {})).must_equal true
|
16
|
+
expect(subject.valid?(nil, {})).must_equal true
|
17
17
|
end
|
18
18
|
|
19
19
|
it "raises an error for values not in the list" do
|
20
|
-
ex =
|
21
|
-
ex.message.must_equal "must be one of Antelope, Bear, Cat, Dog, or Elephant, not Albatross"
|
20
|
+
ex = expect { subject.valid?("Albatross", {}) }.must_raise InvalidInputError
|
21
|
+
expect(ex.message).must_equal "must be one of Antelope, Bear, Cat, Dog, or Elephant, not Albatross"
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -8,12 +8,12 @@ module Hermod
|
|
8
8
|
end
|
9
9
|
|
10
10
|
it "permits attributes in the list" do
|
11
|
-
subject.valid?(nil, {species: "Felis catus", genus: "Felis"}).must_equal true
|
11
|
+
expect(subject.valid?(nil, {species: "Felis catus", genus: "Felis"})).must_equal true
|
12
12
|
end
|
13
13
|
|
14
14
|
it "raises an error for attributes not in the list" do
|
15
|
-
ex =
|
16
|
-
ex.message.must_equal "has attributes it doesn't accept: phylum"
|
15
|
+
ex = expect { subject.valid?(nil, {phylum: "Chordata"}) }.must_raise InvalidInputError
|
16
|
+
expect(ex.message).must_equal "has attributes it doesn't accept: phylum"
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
@@ -8,7 +8,7 @@ module Hermod
|
|
8
8
|
end
|
9
9
|
|
10
10
|
it "doesn't implement a test" do
|
11
|
-
|
11
|
+
expect { subject.valid?(nil, {}) }.must_raise NotImplementedError
|
12
12
|
end
|
13
13
|
|
14
14
|
it "has a default error message" do
|
@@ -17,8 +17,8 @@ module Hermod
|
|
17
17
|
false
|
18
18
|
end
|
19
19
|
end
|
20
|
-
ex =
|
21
|
-
ex.message.must_equal "is invalid"
|
20
|
+
ex = expect { TestValidator.new.valid?(nil, {}) }.must_raise InvalidInputError
|
21
|
+
expect(ex.message).must_equal "is invalid"
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -8,20 +8,20 @@ module Hermod
|
|
8
8
|
end
|
9
9
|
|
10
10
|
it "allows positive values" do
|
11
|
-
subject.valid?(1, {}).must_equal true
|
11
|
+
expect(subject.valid?(1, {})).must_equal true
|
12
12
|
end
|
13
13
|
|
14
14
|
it "allows zero values" do
|
15
|
-
subject.valid?(0, {}).must_equal true
|
15
|
+
expect(subject.valid?(0, {})).must_equal true
|
16
16
|
end
|
17
17
|
|
18
18
|
it "allows blank values" do
|
19
|
-
subject.valid?(nil, {}).must_equal true
|
19
|
+
expect(subject.valid?(nil, {})).must_equal true
|
20
20
|
end
|
21
21
|
|
22
22
|
it "raises an error for negative values" do
|
23
|
-
ex =
|
24
|
-
ex.message.must_equal "cannot be negative"
|
23
|
+
ex = expect { subject.valid?(-1, {}) }.must_raise InvalidInputError
|
24
|
+
expect(ex.message).must_equal "cannot be negative"
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
@@ -8,20 +8,20 @@ module Hermod
|
|
8
8
|
end
|
9
9
|
|
10
10
|
it "allows positive values" do
|
11
|
-
subject.valid?(1, {}).must_equal true
|
11
|
+
expect(subject.valid?(1, {})).must_equal true
|
12
12
|
end
|
13
13
|
|
14
14
|
it "allows negative values" do
|
15
|
-
subject.valid?(-1, {}).must_equal true
|
15
|
+
expect(subject.valid?(-1, {})).must_equal true
|
16
16
|
end
|
17
17
|
|
18
18
|
it "allows blank values" do
|
19
|
-
subject.valid?(nil, {}).must_equal true
|
19
|
+
expect(subject.valid?(nil, {})).must_equal true
|
20
20
|
end
|
21
21
|
|
22
22
|
it "raises an error for zero values" do
|
23
|
-
ex =
|
24
|
-
ex.message.must_equal "cannot be zero"
|
23
|
+
ex = expect { subject.valid?(0, {}) }.must_raise InvalidInputError
|
24
|
+
expect(ex.message).must_equal "cannot be zero"
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
@@ -8,21 +8,21 @@ module Hermod
|
|
8
8
|
end
|
9
9
|
|
10
10
|
it "allows values in the range" do
|
11
|
-
subject.valid?(1, {}).must_equal true
|
12
|
-
subject.valid?(7, {}).must_equal true
|
11
|
+
expect(subject.valid?(1, {})).must_equal true
|
12
|
+
expect(subject.valid?(7, {})).must_equal true
|
13
13
|
end
|
14
14
|
|
15
15
|
it "allows blank values" do
|
16
|
-
subject.valid?(nil, {}).must_equal true
|
16
|
+
expect(subject.valid?(nil, {})).must_equal true
|
17
17
|
end
|
18
18
|
|
19
19
|
it "raises an error for values outwith the range" do
|
20
|
-
ex =
|
21
|
-
ex.message.must_equal "must be between 1 and 7"
|
20
|
+
ex = expect { subject.valid?(0, {}) }.must_raise InvalidInputError
|
21
|
+
expect(ex.message).must_equal "must be between 1 and 7"
|
22
22
|
end
|
23
23
|
|
24
24
|
it "can also take a min and max as arguments" do
|
25
|
-
Range.new(1, 7).valid?(3, {}).must_equal true
|
25
|
+
expect(Range.new(1, 7).valid?(3, {})).must_equal true
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
@@ -8,17 +8,17 @@ module Hermod
|
|
8
8
|
end
|
9
9
|
|
10
10
|
it "allows values that match the pattern" do
|
11
|
-
subject.valid?("AB123456C", {}).must_equal true
|
11
|
+
expect(subject.valid?("AB123456C", {})).must_equal true
|
12
12
|
end
|
13
13
|
|
14
14
|
it "allows blank values" do
|
15
|
-
subject.valid?("", {}).must_equal true
|
16
|
-
subject.valid?(nil, {}).must_equal true
|
15
|
+
expect(subject.valid?("", {})).must_equal true
|
16
|
+
expect(subject.valid?(nil, {})).must_equal true
|
17
17
|
end
|
18
18
|
|
19
19
|
it "raises an error for values that don't match the pattern" do
|
20
|
-
ex =
|
21
|
-
ex.message.must_equal "\"fish\" does not match /\\A[A-Z]{2} [0-9]{6} [A-D]\\z/x"
|
20
|
+
ex = expect { subject.valid?("fish", {}) }.must_raise InvalidInputError
|
21
|
+
expect(ex.message).must_equal "\"fish\" does not match /\\A[A-Z]{2} [0-9]{6} [A-D]\\z/x"
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -5,27 +5,27 @@ module Hermod
|
|
5
5
|
describe TypeChecker do
|
6
6
|
it "uses a default block that checks the value is an instance of the given class" do
|
7
7
|
checker = TypeChecker.new(Integer)
|
8
|
-
checker.valid?(1, {}).must_equal true
|
9
|
-
|
8
|
+
expect(checker.valid?(1, {})).must_equal true
|
9
|
+
expect { checker.valid?(1.0, {}) }.must_raise InvalidInputError
|
10
10
|
end
|
11
11
|
|
12
12
|
it "allows you to give a block to be more discerning" do
|
13
13
|
checker = TypeChecker.new(Integer) { |val| val > 0 }
|
14
|
-
checker.valid?(5, {}).must_equal true
|
15
|
-
|
14
|
+
expect(checker.valid?(5, {})).must_equal true
|
15
|
+
expect { checker.valid?(-2, {}) }.must_raise InvalidInputError
|
16
16
|
end
|
17
17
|
|
18
18
|
it "ignores blank values" do
|
19
19
|
checker = TypeChecker.new(Integer)
|
20
|
-
checker.valid?(nil, {}).must_equal true
|
20
|
+
expect(checker.valid?(nil, {})).must_equal true
|
21
21
|
end
|
22
22
|
|
23
23
|
it "gives the correct message" do
|
24
|
-
ex =
|
25
|
-
ex.message.must_equal "must be an integer"
|
24
|
+
ex = expect { TypeChecker.new(Integer).valid?(1.0, {}) }.must_raise InvalidInputError
|
25
|
+
expect(ex.message).must_equal "must be an integer"
|
26
26
|
|
27
|
-
ex =
|
28
|
-
ex.message.must_equal "must be a float"
|
27
|
+
ex = expect { TypeChecker.new(Float).valid?(1, {}) }.must_raise InvalidInputError
|
28
|
+
expect(ex.message).must_equal "must be a float"
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
@@ -8,12 +8,12 @@ module Hermod
|
|
8
8
|
end
|
9
9
|
|
10
10
|
it "allows values that are present" do
|
11
|
-
subject.valid?(1, {}).must_equal true
|
11
|
+
expect(subject.valid?(1, {})).must_equal true
|
12
12
|
end
|
13
13
|
|
14
14
|
it "raises an error for missing values" do
|
15
|
-
ex =
|
16
|
-
ex.message.must_equal "isn't optional but no value was provided"
|
15
|
+
ex = expect { subject.valid?(nil, {}) }.must_raise InvalidInputError
|
16
|
+
expect(ex.message).must_equal "isn't optional but no value was provided"
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
@@ -8,16 +8,16 @@ module Hermod
|
|
8
8
|
end
|
9
9
|
|
10
10
|
it "allows values that are in whole units" do
|
11
|
-
subject.valid?(1.0, {}).must_equal true
|
11
|
+
expect(subject.valid?(1.0, {})).must_equal true
|
12
12
|
end
|
13
13
|
|
14
14
|
it "allows blank values" do
|
15
|
-
subject.valid?(nil, {}).must_equal true
|
15
|
+
expect(subject.valid?(nil, {})).must_equal true
|
16
16
|
end
|
17
17
|
|
18
18
|
it "raises an error for values with a fractional componant" do
|
19
|
-
ex =
|
20
|
-
ex.message.must_equal "must be in whole units"
|
19
|
+
ex = expect { subject.valid?(3.1415, {}) }.must_raise InvalidInputError
|
20
|
+
expect(ex.message).must_equal "must be in whole units"
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
@@ -16,16 +16,16 @@ module Hermod
|
|
16
16
|
end
|
17
17
|
|
18
18
|
it "should format the date with the given date string" do
|
19
|
-
value_of_node("DateOfBirth").must_equal "1988-08-13"
|
19
|
+
expect(value_of_node("DateOfBirth")).must_equal "1988-08-13"
|
20
20
|
end
|
21
21
|
|
22
22
|
it "should raise an error if given something that isn't a date" do
|
23
|
-
|
23
|
+
expect { subject.anniversary "yesterday" }.must_raise InvalidInputError
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should ignore blank dates if the date is optional" do
|
27
27
|
subject.anniversary nil
|
28
|
-
nodes("Anniversary").must_be_empty
|
28
|
+
expect(nodes("Anniversary")).must_be_empty
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
@@ -16,16 +16,16 @@ module Hermod
|
|
16
16
|
end
|
17
17
|
|
18
18
|
it "should format the datetime with the given format string" do
|
19
|
-
value_of_node("Published").must_equal "2015-03-14 12:30:56"
|
19
|
+
expect(value_of_node("Published")).must_equal "2015-03-14 12:30:56"
|
20
20
|
end
|
21
21
|
|
22
22
|
it "should raise an error if given something that isn't a date" do
|
23
|
-
|
23
|
+
expect { subject.redacted "yesterday" }.must_raise InvalidInputError
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should ignore blank dates if the date is optional" do
|
27
27
|
subject.redacted nil
|
28
|
-
nodes("Redacted").must_be_empty
|
28
|
+
expect(nodes("Redacted")).must_be_empty
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
@@ -14,15 +14,15 @@ module Hermod
|
|
14
14
|
|
15
15
|
it "should accept a valid number" do
|
16
16
|
subject.day_of_the_week 7
|
17
|
-
value_of_node("DayOfTheWeek").must_equal "7"
|
17
|
+
expect(value_of_node("DayOfTheWeek")).must_equal "7"
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should raise an error if the number is above the maximum" do
|
21
|
-
|
21
|
+
expect { subject.day_of_the_week 8 }.must_raise InvalidInputError
|
22
22
|
end
|
23
23
|
|
24
24
|
it "should raise an error if the number is below the minimum" do
|
25
|
-
|
25
|
+
expect { subject.day_of_the_week 0 }.must_raise InvalidInputError
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
@@ -20,44 +20,44 @@ module Hermod
|
|
20
20
|
end
|
21
21
|
|
22
22
|
it "should format values with the provided format string" do
|
23
|
-
value_of_node("Pay").must_equal "123.45"
|
23
|
+
expect(value_of_node("Pay")).must_equal "123.45"
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should not include optional nodes if they're zero" do
|
27
|
-
number_of_nodes("Tax").must_equal 0
|
27
|
+
expect(number_of_nodes("Tax")).must_equal 0
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should use xml_name as the node name if provided" do
|
31
31
|
subject.ni 100
|
32
|
-
number_of_nodes("NI").must_equal 1
|
32
|
+
expect(number_of_nodes("NI")).must_equal 1
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should raise an error if given a negative number for a field that cannot be negative" do
|
36
|
-
ex =
|
37
|
-
ex.message.must_equal "ni cannot be negative"
|
36
|
+
ex = expect { subject.ni(-100) }.must_raise InvalidInputError
|
37
|
+
expect(ex.message).must_equal "ni cannot be negative"
|
38
38
|
end
|
39
39
|
|
40
40
|
it "should allow negative numbers for fields by default" do
|
41
41
|
subject.pension(-100)
|
42
|
-
value_of_node("Pension").must_equal "-100.00"
|
42
|
+
expect(value_of_node("Pension")).must_equal "-100.00"
|
43
43
|
end
|
44
44
|
|
45
45
|
it "should not allow decimal values for whole unit nodes" do
|
46
|
-
ex =
|
47
|
-
ex.message.must_equal "pension must be in whole units"
|
46
|
+
ex = expect { subject.pension BigDecimal("12.34") }.must_raise InvalidInputError
|
47
|
+
expect(ex.message).must_equal "pension must be in whole units"
|
48
48
|
end
|
49
49
|
|
50
50
|
it "should not allow zero for nodes that disallow it" do
|
51
|
-
ex =
|
52
|
-
ex.message.must_equal "student_loan cannot be zero"
|
51
|
+
ex = expect { subject.student_loan 0 }.must_raise Hermod::InvalidInputError
|
52
|
+
expect(ex.message).must_equal "student_loan cannot be zero"
|
53
53
|
end
|
54
54
|
|
55
55
|
it "should treat blank nodes as zero nodes" do
|
56
56
|
subject.ni nil
|
57
|
-
value_of_node("NI").must_equal "0.00"
|
57
|
+
expect(value_of_node("NI")).must_equal "0.00"
|
58
58
|
|
59
59
|
subject.tax nil
|
60
|
-
nodes("Tax").must_be_empty
|
60
|
+
expect(nodes("Tax")).must_be_empty
|
61
61
|
end
|
62
62
|
end
|
63
63
|
end
|
@@ -21,7 +21,7 @@ module Hermod
|
|
21
21
|
|
22
22
|
it "should correctly wrap the inner XML" do
|
23
23
|
expected = "<ParentXml>\n <InnerXml>\n <Inside>layered like an onion</Inside>\n </InnerXml>\n</ParentXml>"
|
24
|
-
subject.to_xml.to_s.must_equal expected
|
24
|
+
expect(subject.to_xml.to_s).must_equal expected
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
@@ -33,43 +33,43 @@ module Hermod
|
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should set node contents correctly" do
|
36
|
-
value_of_node("Greeting").must_equal "Hello"
|
36
|
+
expect(value_of_node("Greeting")).must_equal "Hello"
|
37
37
|
end
|
38
38
|
|
39
39
|
it "should allow values that pass the regex validation" do
|
40
40
|
subject.title "Sir"
|
41
|
-
value_of_node("Title").must_equal "Sir"
|
41
|
+
expect(value_of_node("Title")).must_equal "Sir"
|
42
42
|
end
|
43
43
|
|
44
44
|
it "should raise an error when the regex validation fails" do
|
45
|
-
ex =
|
46
|
-
ex.message.must_equal %(title "Laird" does not match /\\ASir|Dame\\z/)
|
45
|
+
ex = expect { subject.title "Laird" }.must_raise InvalidInputError
|
46
|
+
expect(ex.message).must_equal %(title "Laird" does not match /\\ASir|Dame\\z/)
|
47
47
|
end
|
48
48
|
|
49
49
|
it "should require all non-optional nodes to have content" do
|
50
|
-
ex =
|
51
|
-
ex.message.must_equal "required isn't optional but no value was provided"
|
50
|
+
ex = expect { subject.required "" }.must_raise InvalidInputError
|
51
|
+
expect(ex.message).must_equal "required isn't optional but no value was provided"
|
52
52
|
end
|
53
53
|
|
54
54
|
it "should apply changes to the inputs if a input_mutator is provided" do
|
55
55
|
subject.gender "Male"
|
56
|
-
value_of_node("Gender").must_equal "M"
|
56
|
+
expect(value_of_node("Gender")).must_equal "M"
|
57
57
|
end
|
58
58
|
|
59
59
|
it "should allow input_mutators to access nodes the instance" do
|
60
60
|
subject.mood "Hangry"
|
61
61
|
subject.status "Eating cookies"
|
62
|
-
value_of_node("Status").must_equal "Eating cookies furiously"
|
62
|
+
expect(value_of_node("Status")).must_equal "Eating cookies furiously"
|
63
63
|
end
|
64
64
|
|
65
65
|
it "should restrict values to those in the list of allowed values if such a list is provided" do
|
66
66
|
subject.mood "Hangry"
|
67
|
-
value_of_node("Mood").must_equal "Hangry"
|
67
|
+
expect(value_of_node("Mood")).must_equal "Hangry"
|
68
68
|
end
|
69
69
|
|
70
70
|
it "should raise an error if the value is not in the list of allowed values" do
|
71
|
-
ex =
|
72
|
-
ex.message.must_equal "mood must be one of Happy, Sad, or Hangry, not Jubilant"
|
71
|
+
ex = expect { subject.mood "Jubilant" }.must_raise InvalidInputError
|
72
|
+
expect(ex.message).must_equal "mood must be one of Happy, Sad, or Hangry, not Jubilant"
|
73
73
|
end
|
74
74
|
|
75
75
|
it "should be thread safe for validation" do
|
@@ -81,23 +81,23 @@ module Hermod
|
|
81
81
|
subject1.mood "Hangry"
|
82
82
|
end
|
83
83
|
|
84
|
-
ex =
|
85
|
-
ex.message.must_equal "mood must be one of Happy, Sad, or Hangry, not Jubilant"
|
84
|
+
ex = expect { subject.mood "Jubilant" }.must_raise InvalidInputError
|
85
|
+
expect(ex.message).must_equal "mood must be one of Happy, Sad, or Hangry, not Jubilant"
|
86
86
|
end
|
87
87
|
|
88
88
|
it "should use the given keys for attributes" do
|
89
89
|
subject.title "Sir", masculine: "no"
|
90
|
-
attributes_for_node("Title").keys.first.must_equal "Male"
|
91
|
-
attributes_for_node("Title")["Male"].value.must_equal "no"
|
90
|
+
expect(attributes_for_node("Title").keys.first).must_equal "Male"
|
91
|
+
expect(attributes_for_node("Title")["Male"].value).must_equal "no"
|
92
92
|
end
|
93
93
|
|
94
94
|
it "should raise an error if given an attribute that isn't expected" do
|
95
|
-
|
95
|
+
expect { subject.title "Sir", knight: "yes" }.must_raise InvalidInputError
|
96
96
|
end
|
97
97
|
|
98
98
|
it "should not include empty, optional nodes" do
|
99
99
|
subject.name ""
|
100
|
-
nodes("Name").must_be_empty
|
100
|
+
expect(nodes("Name")).must_be_empty
|
101
101
|
end
|
102
102
|
end
|
103
103
|
end
|
@@ -16,7 +16,7 @@ module Hermod
|
|
16
16
|
end
|
17
17
|
|
18
18
|
it "should include the node with yes as the contents" do
|
19
|
-
value_of_node("Awesome").must_equal "yes"
|
19
|
+
expect(value_of_node("Awesome")).must_equal "yes"
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
@@ -28,7 +28,7 @@ module Hermod
|
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should include the node with no as the contents" do
|
31
|
-
value_of_node("Awesome").must_equal "no"
|
31
|
+
expect(value_of_node("Awesome")).must_equal "no"
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
@@ -16,7 +16,7 @@ module Hermod
|
|
16
16
|
end
|
17
17
|
|
18
18
|
it "should include the node with yes as the contents" do
|
19
|
-
value_of_node("Awesome").must_equal "yes"
|
19
|
+
expect(value_of_node("Awesome")).must_equal "yes"
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
@@ -28,7 +28,7 @@ module Hermod
|
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should not include the node" do
|
31
|
-
number_of_nodes("Awesome").must_equal 0
|
31
|
+
expect(number_of_nodes("Awesome")).must_equal 0
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
@@ -21,7 +21,7 @@ module Hermod
|
|
21
21
|
end
|
22
22
|
|
23
23
|
it "should use the class name as the XML node name" do
|
24
|
-
subject.to_xml.name.must_equal "UnnamedXML"
|
24
|
+
expect(subject.to_xml.name).must_equal "UnnamedXML"
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -31,7 +31,7 @@ module Hermod
|
|
31
31
|
end
|
32
32
|
|
33
33
|
it "should use the class name as the XML node name" do
|
34
|
-
subject.to_xml.name.must_equal "Testing"
|
34
|
+
expect(subject.to_xml.name).must_equal "Testing"
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
@@ -44,11 +44,11 @@ module Hermod
|
|
44
44
|
end
|
45
45
|
|
46
46
|
it "formats dates in yyyy-mm-dd form" do
|
47
|
-
value_of_node("Birthday").must_equal("1988-08-13")
|
47
|
+
expect(value_of_node("Birthday")).must_equal("1988-08-13")
|
48
48
|
end
|
49
49
|
|
50
50
|
it "formats money to two decimal places" do
|
51
|
-
value_of_node("Allowance").must_equal("20.00")
|
51
|
+
expect(value_of_node("Allowance")).must_equal("20.00")
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
@@ -63,32 +63,32 @@ module Hermod
|
|
63
63
|
end
|
64
64
|
|
65
65
|
it "should order nodes by the order they were defined when the class was built" do
|
66
|
-
node_by_index(0).name.must_equal "First"
|
67
|
-
node_by_index(0).content.must_equal "alpha"
|
66
|
+
expect(node_by_index(0).name).must_equal "First"
|
67
|
+
expect(node_by_index(0).content).must_equal "alpha"
|
68
68
|
|
69
|
-
node_by_index(1).name.must_equal "Repeated"
|
70
|
-
node_by_index(1).content.must_equal "beta"
|
69
|
+
expect(node_by_index(1).name).must_equal "Repeated"
|
70
|
+
expect(node_by_index(1).content).must_equal "beta"
|
71
71
|
|
72
|
-
node_by_index(-1).name.must_equal "Last"
|
73
|
-
node_by_index(-1).content.must_equal "epsilon"
|
72
|
+
expect(node_by_index(-1).name).must_equal "Last"
|
73
|
+
expect(node_by_index(-1).content).must_equal "epsilon"
|
74
74
|
end
|
75
75
|
|
76
76
|
it "should order nodes called multiple times in the order they were called" do
|
77
|
-
node_by_index(1).name.must_equal "Repeated"
|
78
|
-
node_by_index(1).content.must_equal "beta"
|
77
|
+
expect(node_by_index(1).name).must_equal "Repeated"
|
78
|
+
expect(node_by_index(1).content).must_equal "beta"
|
79
79
|
|
80
|
-
node_by_index(2).name.must_equal "Repeated"
|
81
|
-
node_by_index(2).content.must_equal "gamma"
|
80
|
+
expect(node_by_index(2).name).must_equal "Repeated"
|
81
|
+
expect(node_by_index(2).content).must_equal "gamma"
|
82
82
|
end
|
83
83
|
|
84
84
|
it "should order nodes at XML generation time, not at call time" do
|
85
85
|
subject.repeated "delta"
|
86
86
|
|
87
|
-
node_by_index(-2).name.must_equal "Repeated"
|
88
|
-
node_by_index(-2).content.must_equal "delta"
|
87
|
+
expect(node_by_index(-2).name).must_equal "Repeated"
|
88
|
+
expect(node_by_index(-2).content).must_equal "delta"
|
89
89
|
|
90
|
-
node_by_index(-1).name.must_equal "Last"
|
91
|
-
node_by_index(-1).content.must_equal "epsilon"
|
90
|
+
expect(node_by_index(-1).name).must_equal "Last"
|
91
|
+
expect(node_by_index(-1).content).must_equal "epsilon"
|
92
92
|
end
|
93
93
|
end
|
94
94
|
end
|
data/spec/hermod_spec.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hermod
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Harry Mills
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-05-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: libxml-ruby
|
@@ -31,9 +31,6 @@ dependencies:
|
|
31
31
|
- - ">"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '3.2'
|
34
|
-
- - "<"
|
35
|
-
- !ruby/object:Gem::Version
|
36
|
-
version: '7'
|
37
34
|
type: :runtime
|
38
35
|
prerelease: false
|
39
36
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -41,9 +38,6 @@ dependencies:
|
|
41
38
|
- - ">"
|
42
39
|
- !ruby/object:Gem::Version
|
43
40
|
version: '3.2'
|
44
|
-
- - "<"
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: '7'
|
47
41
|
- !ruby/object:Gem::Dependency
|
48
42
|
name: bundler
|
49
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -78,48 +72,48 @@ dependencies:
|
|
78
72
|
requirements:
|
79
73
|
- - "~>"
|
80
74
|
- !ruby/object:Gem::Version
|
81
|
-
version: '5.
|
75
|
+
version: '5.15'
|
82
76
|
type: :development
|
83
77
|
prerelease: false
|
84
78
|
version_requirements: !ruby/object:Gem::Requirement
|
85
79
|
requirements:
|
86
80
|
- - "~>"
|
87
81
|
- !ruby/object:Gem::Version
|
88
|
-
version: '5.
|
82
|
+
version: '5.15'
|
89
83
|
- !ruby/object:Gem::Dependency
|
90
84
|
name: minitest-reporters
|
91
85
|
requirement: !ruby/object:Gem::Requirement
|
92
86
|
requirements:
|
93
|
-
- - "~>"
|
94
|
-
- !ruby/object:Gem::Version
|
95
|
-
version: '1.0'
|
96
87
|
- - ">="
|
97
88
|
- !ruby/object:Gem::Version
|
98
89
|
version: 1.0.16
|
90
|
+
- - "~>"
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '1.5'
|
99
93
|
type: :development
|
100
94
|
prerelease: false
|
101
95
|
version_requirements: !ruby/object:Gem::Requirement
|
102
96
|
requirements:
|
103
|
-
- - "~>"
|
104
|
-
- !ruby/object:Gem::Version
|
105
|
-
version: '1.0'
|
106
97
|
- - ">="
|
107
98
|
- !ruby/object:Gem::Version
|
108
99
|
version: 1.0.16
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '1.5'
|
109
103
|
- !ruby/object:Gem::Dependency
|
110
104
|
name: nokogiri
|
111
105
|
requirement: !ruby/object:Gem::Requirement
|
112
106
|
requirements:
|
113
107
|
- - "~>"
|
114
108
|
- !ruby/object:Gem::Version
|
115
|
-
version: '1.
|
109
|
+
version: '1.13'
|
116
110
|
type: :development
|
117
111
|
prerelease: false
|
118
112
|
version_requirements: !ruby/object:Gem::Requirement
|
119
113
|
requirements:
|
120
114
|
- - "~>"
|
121
115
|
- !ruby/object:Gem::Version
|
122
|
-
version: '1.
|
116
|
+
version: '1.13'
|
123
117
|
description: |-
|
124
118
|
A Ruby library for talking to the HMRC Government Gateway.
|
125
119
|
This provides a builder for creating classes that can generate the XML needed complete with type information and
|
@@ -130,13 +124,14 @@ executables: []
|
|
130
124
|
extensions: []
|
131
125
|
extra_rdoc_files: []
|
132
126
|
files:
|
127
|
+
- ".github/workflows/freeagent-gem.yml"
|
128
|
+
- ".github/workflows/reviewdog.yml"
|
133
129
|
- ".gitignore"
|
134
130
|
- ".ruby-version"
|
135
131
|
- ".travis.yml"
|
136
132
|
- CHANGELOG.md
|
137
133
|
- Gemfile
|
138
134
|
- Guardfile
|
139
|
-
- Jenkinsfile
|
140
135
|
- LICENSE
|
141
136
|
- README.md
|
142
137
|
- Rakefile
|
@@ -188,6 +183,7 @@ homepage: https://github.com/fac/hermod
|
|
188
183
|
licenses:
|
189
184
|
- Apache License, Version 2.0
|
190
185
|
metadata:
|
186
|
+
allowed_push_host: https://rubygems.org
|
191
187
|
bug_tracker_uri: https://github.com/fac/hermod/issues
|
192
188
|
changelog_uri: https://github.com/fac/hermod/blob/master/CHANGELOG.md
|
193
189
|
source_code_uri: https://github.com/fac/hermod
|
@@ -207,7 +203,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
207
203
|
- !ruby/object:Gem::Version
|
208
204
|
version: '0'
|
209
205
|
requirements: []
|
210
|
-
rubygems_version: 3.
|
206
|
+
rubygems_version: 3.2.32
|
211
207
|
signing_key:
|
212
208
|
specification_version: 4
|
213
209
|
summary: A Ruby library for talking to the HMRC Government Gateway.
|