rspec-forward 0.1.3 → 0.1.4

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: 1b3205b7050cdf8f0bef33291f5015b5e345757ea3ebfa39338f370e7bdcb071
4
+ data.tar.gz: 473a350e1c4f61586f7804d23a29c854045a96c5ce7848d0350c80d007132514
5
5
  SHA512:
6
- metadata.gz: a7ee7bd5497d5cc0a72683a6824a16ffbbb387ef0ec65da077340b8d73e8f364da430a5625aca8884033315bceefb96b2706972b6302595047ba45b82d86e0ff
7
- data.tar.gz: b5f350f737944f9b6c408c52dba44df02e096a1e98f8dc84f36d0ebae628d54ee4b141936f1e009b2d5f69de1ecefd13d11296a7d3b10a48f86c23c1f13f1333
6
+ metadata.gz: a0682f9ce361a22f8b9115d1edee289f09b0c5dd4d87591f361690fc065505db1d38492805291ccad5486a0eb616e6430f5387e6781f98b73a89a6c0aecdbbfb
7
+ data.tar.gz: 0b14a346a42976da92a7f7534aae05edab58d1b25633ddf3cb34b71f5ccaef6e738e6ff11026f8325d613b8da485858d1a617616f1fe047a8aad13f539ea8a1e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rspec-forward (0.1.3)
4
+ rspec-forward (0.1.4)
5
5
  rspec-mocks (~> 3.10)
6
6
 
7
7
  GEM
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,110 @@ 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 calss 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(:object) { described_class }
91
+
92
+ it "passes arguments to instance" do
93
+ expect(object)
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
+ # ...
108
+
109
+ it { should forward_to_instance(:call).with_named(:foo, :bar) }
110
+ it { should forward_to_instance(:call).with_1_arg_and_named(:foo) }
111
+ it { should forward_to_instance(:call).with_2_args_and_named(:foo) }
112
+ it { should forward_to_instance(:call).with_3_args_and_named(:foo, :bar) }
113
+ ```
114
+
115
+ TODO: Explain `forward_to_instance_build(...)`
116
+
117
+ ## Development
118
+
119
+ After checking out the repo, run `bundle install` to install dependencies. Then, run
120
+ `bundle exec rspec` to run the tests.
121
+
122
+ ## Contributing
36
123
 
124
+ Bug reports and pull requests are welcome on GitHub at
125
+ https://github.com/adlugopolski/rspec-forward.
37
126
 
38
127
  ## License
39
128
 
@@ -41,4 +130,6 @@ The gem is available as open source under the terms of the [MIT License](https:/
41
130
 
42
131
  ## Code of Conduct
43
132
 
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).
133
+ Everyone interacting in the RSpec::Forward project's codebases, issue
134
+ trackers, chat rooms and mailing lists is expected to follow the [code of
135
+ conduct](https://github.com/adlugopolski/rspec-forward/blob/master/CODE_OF_CONDUCT.md).
@@ -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.4"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
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.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aleksader Długopolski