rspec-forward 0.1.3 → 0.1.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e27a0fd49193261eaee3dce78cf62baf5466ecdf4026b016f7715008fea3b629
4
- data.tar.gz: b01d40a1b73bcf6cf870e10b25aad20bbf5def7d20e536a8dfb1db415b3c6189
3
+ metadata.gz: 60586a2b506f34e4fe653293535ece8b206d47923a3fef6b0c2adfa5b82005ce
4
+ data.tar.gz: 6c3384494e394a33996bc1580f15d3a3ae6d7a1976b196e98fd2ad1f73672c2a
5
5
  SHA512:
6
- metadata.gz: a7ee7bd5497d5cc0a72683a6824a16ffbbb387ef0ec65da077340b8d73e8f364da430a5625aca8884033315bceefb96b2706972b6302595047ba45b82d86e0ff
7
- data.tar.gz: b5f350f737944f9b6c408c52dba44df02e096a1e98f8dc84f36d0ebae628d54ee4b141936f1e009b2d5f69de1ecefd13d11296a7d3b10a48f86c23c1f13f1333
6
+ metadata.gz: 39019b0a6c054365e0f5e26d39f3081e07d91db3a42bcbf60d57f3907cd92761cf530e905916227f5919c2959a6e3f7c984960e3fc068ddc216159a2f324a6b2
7
+ data.tar.gz: 46d07febe0734cc50532a5cf8c3772541153c47e98391c7f8a2b30f9b97670a8e98c633d02e22edacda53ace9b828f80cf6a4b243e5f2c14f703b66b3d479408
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.0.0
data/Gemfile.lock CHANGED
@@ -1,17 +1,17 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rspec-forward (0.1.3)
5
- rspec-mocks (~> 3.10)
4
+ rspec-forward (0.1.6)
5
+ rspec-mocks (~> 3.9)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
10
  coderay (1.1.3)
11
11
  diff-lcs (1.4.4)
12
- ffi (1.15.0)
13
- formatador (0.2.5)
14
- guard (2.16.2)
12
+ ffi (1.15.3)
13
+ formatador (0.3.0)
14
+ guard (2.17.0)
15
15
  formatador (>= 0.2.4)
16
16
  listen (>= 2.7, < 4.0)
17
17
  lumberjack (>= 1.0.12, < 2.0)
@@ -25,7 +25,7 @@ GEM
25
25
  guard (~> 2.1)
26
26
  guard-compat (~> 1.1)
27
27
  rspec (>= 2.99.0, < 4.0)
28
- listen (3.4.1)
28
+ listen (3.5.1)
29
29
  rb-fsevent (~> 0.10, >= 0.10.3)
30
30
  rb-inotify (~> 0.9, >= 0.9.10)
31
31
  lumberjack (1.2.8)
@@ -34,26 +34,26 @@ GEM
34
34
  notiffany (0.1.3)
35
35
  nenv (~> 0.1)
36
36
  shellany (~> 0.0)
37
- pry (0.14.0)
37
+ pry (0.14.1)
38
38
  coderay (~> 1.1)
39
39
  method_source (~> 1.0)
40
40
  rake (12.3.3)
41
- rb-fsevent (0.10.4)
41
+ rb-fsevent (0.11.0)
42
42
  rb-inotify (0.10.1)
43
43
  ffi (~> 1.0)
44
44
  rspec (3.10.0)
45
45
  rspec-core (~> 3.10.0)
46
46
  rspec-expectations (~> 3.10.0)
47
47
  rspec-mocks (~> 3.10.0)
48
- rspec-core (3.10.0)
48
+ rspec-core (3.10.1)
49
49
  rspec-support (~> 3.10.0)
50
- rspec-expectations (3.10.0)
50
+ rspec-expectations (3.10.1)
51
51
  diff-lcs (>= 1.2.0, < 2.0)
52
52
  rspec-support (~> 3.10.0)
53
- rspec-mocks (3.10.0)
53
+ rspec-mocks (3.10.2)
54
54
  diff-lcs (>= 1.2.0, < 2.0)
55
55
  rspec-support (~> 3.10.0)
56
- rspec-support (3.10.0)
56
+ rspec-support (3.10.2)
57
57
  shellany (0.0.1)
58
58
  thor (1.1.0)
59
59
 
@@ -68,4 +68,4 @@ DEPENDENCIES
68
68
  rspec-forward!
69
69
 
70
70
  BUNDLED WITH
71
- 2.1.4
71
+ 2.2.3
data/Guardfile CHANGED
@@ -4,7 +4,7 @@
4
4
  GUARD_OPTIONS = {
5
5
  failed_mode: :keep,
6
6
  cmd: "rspec --order rand:$RANDOM",
7
- title: "RSpec",
7
+ title: "RSpec"
8
8
  }.freeze
9
9
 
10
10
  guard :rspec, GUARD_OPTIONS do
@@ -15,11 +15,11 @@ guard :rspec, GUARD_OPTIONS do
15
15
  watch(%r{^lib/(.+)\.rb$}) do |m|
16
16
  "spec/#{m[1]}_spec.rb"
17
17
  end
18
-
18
+
19
19
  watch("spec/spec_helper.rb") do
20
20
  "spec"
21
21
  end
22
-
22
+
23
23
  watch(%r{^spec/support/(.+)\.rb$}) do
24
24
  "spec"
25
25
  end
data/README.md CHANGED
@@ -1,15 +1,14 @@
1
1
  # RSpec::Forward
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rspec/forward`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ Gem `rspec-forward` adds simple matchers to verify short hand class proxy
4
+ method forwarding when using Method Object pattern.
6
5
 
7
6
  ## Installation
8
7
 
9
8
  Add this line to your application's Gemfile:
10
9
 
11
10
  ```ruby
12
- gem 'rspec-forward'
11
+ gem "rspec-forward"
13
12
  ```
14
13
 
15
14
  And then execute:
@@ -20,20 +19,108 @@ Or install it yourself as:
20
19
 
21
20
  $ gem install rspec-forward
22
21
 
22
+
23
+ Next, include matchers in your `spec/rails_helper.rb` or `spec/spec_helper.rb` in the
24
+ `RSpec.configure` block:
25
+
26
+ ```ruby
27
+ RSpec.configure do |config|
28
+ # ...
29
+ config.include RSpec::Forward
30
+ # ...
31
+ end
32
+ ```
33
+
34
+ If you are using [Spring](https://github.com/rails/spring) for your Rails
35
+ development, make sure the daemon is restarted after the instalation step is
36
+ complete: `spring stop`.
37
+
23
38
  ## Usage
24
39
 
25
- TODO: Write usage instructions here
40
+ Assume you have a Method Object with `#call` method defined like this:
26
41
 
27
- ## Development
42
+ ```ruby
43
+ class Add
44
+ def self.call(...)
45
+ new(...).call
46
+ end
47
+
48
+ def initialize(addend1, addend2)
49
+ @addend1 = addend1
50
+ @addend2 = addend2
51
+ end
52
+
53
+ def call
54
+ @addend1 + @addend2
55
+ end
56
+ end
57
+
58
+ Add.call(3, 5) # => 8
59
+ ```
28
60
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
61
+ Gem `rspec-forward` adds matcher `forward_to_instance` to verify if the
62
+ call using Class Methods is properly building the instance of the class and
63
+ forwarding the method call to expected instance method.
30
64
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
65
+ ```ruby
66
+ require "rails_helper"
32
67
 
33
- ## Contributing
68
+ RSpec.describe Add do
69
+ describe "#call" do
70
+ let(:service) { described_class.new(3, 5) }
34
71
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rspec-forward. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/rspec-forward/blob/master/CODE_OF_CONDUCT.md).
72
+ it "adds numbers" do
73
+ expect(service.call).to eq 8
74
+ end
75
+ end
76
+
77
+ describe ".call" do
78
+ subject { described_class }
79
+
80
+ it { should forward_to_instance(:call).with_2_args }
81
+ end
82
+ end
83
+ ```
84
+
85
+ If you would rather not use the old, deprecated
86
+ `should` syntax in RSpec, replace the above exaple with the following:
87
+
88
+ ```ruby
89
+ describe ".call" do
90
+ let(:klass) { described_class }
91
+
92
+ it "passes arguments to instance" do
93
+ expect(klass)
94
+ .to forward_to_instance(:call)
95
+ .with_2_args
96
+ end
97
+ end
98
+ ```
99
+
100
+ Possible calls to the matcher include the following:
101
+
102
+ ```ruby
103
+ it { should forward_to_instance(:call).with_no_args }
104
+ it { should forward_to_instance(:call).with_1_arg }
105
+ it { should forward_to_instance(:call).with_2_args }
106
+ it { should forward_to_instance(:call).with_3_args }
107
+ it { should forward_to_instance(:call).with_named(:foo, :bar) }
108
+ it { should forward_to_instance(:call).with_1_arg_and_named(:foo) }
109
+ it { should forward_to_instance(:call).with_2_args_and_named(:foo) }
110
+ it { should forward_to_instance(:call).with_3_args_and_named(:foo, :bar) }
111
+ ```
112
+
113
+ **TODO**: Explain `forward_to_instance_build(...)`
114
+
115
+ ## Development
116
+
117
+ After checking out the repo, run `bundle install` to install dependencies. Then, run
118
+ `bundle exec rspec` to run the tests.
119
+
120
+ ## Contributing
36
121
 
122
+ Bug reports and pull requests are welcome on GitHub at
123
+ https://github.com/marzdrel/rspec-forward.
37
124
 
38
125
  ## License
39
126
 
@@ -41,4 +128,6 @@ The gem is available as open source under the terms of the [MIT License](https:/
41
128
 
42
129
  ## Code of Conduct
43
130
 
44
- Everyone interacting in the RSpec::Forward project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/rspec-forward/blob/master/CODE_OF_CONDUCT.md).
131
+ Everyone interacting in the RSpec::Forward project's codebases, issue
132
+ trackers, chat rooms and mailing lists is expected to follow the [code of
133
+ conduct](https://github.com/marzdrel/rspec-forward/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile CHANGED
@@ -3,11 +3,13 @@ require "rspec/core/rake_task"
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task :default => :spec
6
+ task default: :spec
7
7
 
8
+ # rubocop:disable Security/Eval
8
9
  def gemspec
9
- @gemspec ||= eval(File.read("rspec-forward.gemspec"), binding, ".gemspec")
10
+ @_gemspec ||= eval(File.read("rspec-forward.gemspec"), binding, ".gemspec")
10
11
  end
12
+ # rubocop:enable Security/Eval
11
13
 
12
14
  desc "Validate the gemspec"
13
15
  task :gemspec do
@@ -15,7 +17,7 @@ task :gemspec do
15
17
  end
16
18
 
17
19
  desc "Build the gem"
18
- task :gem => :gemspec do
20
+ task gem: :gemspec do
19
21
  sh "gem build #{gemspec.name}.gemspec"
20
22
 
21
23
  FileUtils.mkdir_p "pkg"
@@ -3,15 +3,28 @@ module ::RSpec
3
3
  module ForwardMethods
4
4
  0.upto(10) do |index|
5
5
  define_method format("with_%<count>d_args", count: index) do
6
+ @kwargs = {}
6
7
  @args = Array.new(index, :arg)
7
8
  self
8
9
  end
10
+
11
+ name = format("with_%<count>d_args_and_named", count: index)
12
+
13
+ define_method name do |*kwargs|
14
+ @args = Array.new(index, :arg)
15
+ @kwargs = Hash[kwargs.map { [_1, _1] }]
16
+ self
17
+ end
9
18
  end
10
19
 
11
20
  def with_1_arg
12
21
  with_1_args
13
22
  end
14
23
 
24
+ def with_1_arg_and_named(*args, **kwargs)
25
+ with_1_args_and_named(*args, **kwargs)
26
+ end
27
+
15
28
  def with_no_args
16
29
  with_0_args
17
30
  end
@@ -22,9 +35,9 @@ module ::RSpec
22
35
  self
23
36
  end
24
37
 
25
- def with_named(**kwargs)
38
+ def with_named(*kwargs)
26
39
  @args = []
27
- @kwargs = kwargs
40
+ @kwargs = Hash[kwargs.map { [_1, _1] }]
28
41
  self
29
42
  end
30
43
 
@@ -13,6 +13,13 @@ module ::RSpec
13
13
  def matches?(actual)
14
14
  matches_for?(actual, :return)
15
15
  end
16
+
17
+ def description
18
+ <<~TXT.gsub(/\n+/, " ")
19
+ to pass the arguments to the constructor of instance and return
20
+ the value returned by the instance method
21
+ TXT
22
+ end
16
23
  end
17
24
  end
18
25
  end
@@ -15,6 +15,13 @@ module ::RSpec
15
15
 
16
16
  matches_for?(actual, instance)
17
17
  end
18
+
19
+ def description
20
+ <<~TXT.gsub(/\n+/, " ")
21
+ to pass the arguments to the constructor of instance, execute
22
+ provided instance method and return the instance of the class
23
+ TXT
24
+ end
18
25
  end
19
26
  end
20
27
  end
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module Forward
3
- VERSION = "0.1.3"
3
+ VERSION = "0.1.6"
4
4
  end
5
5
  end
@@ -3,16 +3,16 @@ require_relative "lib/rspec/forward/version"
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "rspec-forward"
5
5
  spec.version = RSpec::Forward::VERSION
6
- spec.authors= ["Aleksader Długopolski"]
7
- spec.email = ["ad@dotpro.org"]
6
+ spec.authors = ["Marz Drel"]
7
+ spec.email = ["marzdrel@dotpro.org"]
8
8
 
9
9
  spec.summary = <<~TXT.gsub(/[[:space:]]+/, " ").strip
10
- Set of RSpec matchers for checking class method to instnace
10
+ Set of RSpec matchers for checking class method to instance
11
11
  method forwarding.
12
12
  TXT
13
13
 
14
14
  spec.description = <<~TXT.gsub(/[[:space:]]+/, " ").strip
15
- Set of RSpec matchers for checking class method to instnace
15
+ Set of RSpec matchers for checking class method to instance
16
16
  method forwarding.
17
17
  TXT
18
18
 
@@ -23,16 +23,16 @@ Gem::Specification.new do |spec|
23
23
  spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
24
24
 
25
25
  # spec.metadata["homepage_uri"] = spec.homepage
26
- spec.metadata["source_code_uri"] =
27
- "https://github.com/adlugopolski/rspec-forward"
26
+ spec.metadata["source_code_uri"] =
27
+ "https://github.com/marzdrel/rspec-forward"
28
28
 
29
- spec.metadata["changelog_uri"] =
30
- "https://github.com/adlugopolski/rspec-forward/blob/master/CHANGELOG.md"
29
+ spec.metadata["changelog_uri"] =
30
+ "https://github.com/marzdrel/rspec-forward/blob/master/CHANGELOG.md"
31
31
 
32
32
  # Specify which files should be added to the gem when it is released.
33
33
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
34
34
 
35
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
35
+ spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
36
36
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
37
37
  end
38
38
 
@@ -40,7 +40,7 @@ Gem::Specification.new do |spec|
40
40
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
41
41
  spec.require_paths = ["lib"]
42
42
 
43
- spec.add_runtime_dependency "rspec-mocks", "~> 3.10"
43
+ spec.add_runtime_dependency "rspec-mocks", "~> 3.9"
44
44
  spec.add_development_dependency "guard", "~> 2.16"
45
45
  spec.add_development_dependency "guard-rspec", "~> 4.7"
46
46
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-forward
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
- - Aleksader Długopolski
8
- autorequire:
7
+ - Marz Drel
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-14 00:00:00.000000000 Z
11
+ date: 2022-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec-mocks
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '3.10'
19
+ version: '3.9'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '3.10'
26
+ version: '3.9'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: guard
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,15 +52,16 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '4.7'
55
- description: Set of RSpec matchers for checking class method to instnace method forwarding.
55
+ description: Set of RSpec matchers for checking class method to instance method forwarding.
56
56
  email:
57
- - ad@dotpro.org
57
+ - marzdrel@dotpro.org
58
58
  executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
62
  - ".gitignore"
63
63
  - ".rspec"
64
+ - ".ruby-version"
64
65
  - ".travis.yml"
65
66
  - CODE_OF_CONDUCT.md
66
67
  - Gemfile
@@ -77,13 +78,13 @@ files:
77
78
  - lib/rspec/forward/forward_to_instance_build.rb
78
79
  - lib/rspec/forward/version.rb
79
80
  - rspec-forward.gemspec
80
- homepage:
81
+ homepage:
81
82
  licenses:
82
83
  - MIT
83
84
  metadata:
84
- source_code_uri: https://github.com/adlugopolski/rspec-forward
85
- changelog_uri: https://github.com/adlugopolski/rspec-forward/blob/master/CHANGELOG.md
86
- post_install_message:
85
+ source_code_uri: https://github.com/marzdrel/rspec-forward
86
+ changelog_uri: https://github.com/marzdrel/rspec-forward/blob/master/CHANGELOG.md
87
+ post_install_message:
87
88
  rdoc_options: []
88
89
  require_paths:
89
90
  - lib
@@ -98,8 +99,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
99
  - !ruby/object:Gem::Version
99
100
  version: '0'
100
101
  requirements: []
101
- rubygems_version: 3.1.4
102
- signing_key:
102
+ rubygems_version: 3.2.3
103
+ signing_key:
103
104
  specification_version: 4
104
- summary: Set of RSpec matchers for checking class method to instnace method forwarding.
105
+ summary: Set of RSpec matchers for checking class method to instance method forwarding.
105
106
  test_files: []