rspice 0.4.3 → 0.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 58dd033ff1703ef7332f30c29da74199a5e2d189866d3521ab7d22ffd69b6226
4
- data.tar.gz: 52843b9f1b591ac03958d303e71bd3a17be19771a0a8e7ad3c8cfdda6afc61e5
3
+ metadata.gz: 651dd42d3b2abbb823d0cf946f2de5a641873756939e1af717f5e1632c673386
4
+ data.tar.gz: 5c23a2024c0402571e8144c8c38e2ae08a228ffe47cf1b846a5fa9b59abe91dd
5
5
  SHA512:
6
- metadata.gz: c64381474bb2a67827046d3eca9b8232ce5c0fcc0c75674e2f0fe023bede31abf6b3a3d2c40b0c9301567a47246e62933e2f4d12503bf88832b0655027f546ae
7
- data.tar.gz: 3f84d07780ca87d314eb77dd590bcd0baaa0041b346405f83ce6c9d6fa7af69c3aed6cf86eea6dbe7699501a3a5d6d19720c7f04c422ddb6baceec1df02529a1
6
+ metadata.gz: d7736fb620d39207483fbb5f8e243917d56cdec97d71d72702c40729b91d87057975164dbf94a55bfdcfa6d295b0d11faac3e16897c35a0a09f5dd7e06d97dde
7
+ data.tar.gz: 1f96d00331b565a1dfddf321067a6e89151f41c122a3c5a0b1698d60e4b570e04de09e9c09b8b1b8215ac1a298b912fe89b38b379f1d78cf3a7934e3d81e7ddd
@@ -1,3 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "rspice/shared_examples/a_class_pass_method"
4
+ require "rspice/shared_examples/a_versioned_spicerack_gem"
@@ -1,36 +1,46 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # TODO: Jank - this should use Method#parameters, not Method#arity
4
-
5
3
  RSpec.shared_examples_for "a class pass method" do |method|
6
4
  subject do
7
- if takes_options?
8
- test_class.public_send(method, *arguments, **options)
5
+ if accepts_block?
6
+ test_class.public_send(method, *arguments, &block)
9
7
  else
10
8
  test_class.public_send(method, *arguments)
11
9
  end
12
10
  end
13
11
 
14
12
  let(:test_class) { described_class }
15
- let(:initialize_arity) { test_class.instance_method(:initialize).arity }
16
- let(:takes_options?) { (initialize_arity < 0) }
17
- let(:argument_arity) { takes_options? ? (initialize_arity.abs - 1) : initialize_arity }
13
+
14
+ let(:method_parameters) { test_class.instance_method(:initialize).parameters }
15
+ let(:argument_arity) { method_parameters.map(&:first).select { |type| type.in?(%i[req opt]) }.length }
16
+ let(:option_keys) { method_parameters.select { |param| param.first.in?(%i[key keyreq]) }.map(&:last) }
17
+ let(:accepts_block?) { method_parameters.any? { |param| param.first == :block } }
18
18
 
19
19
  let(:arguments) do
20
- Array.new(argument_arity) { double }
20
+ Array.new(argument_arity) { double }.tap do |array|
21
+ array << options if options.present?
22
+ end
21
23
  end
22
- let(:options) { takes_options? ? Hash[*Faker::Lorem.words(2 * rand(1..2))].symbolize_keys : nil }
24
+ let(:options) { option_keys.each_with_object({}) { |key, hash| hash[key] = Faker::Lorem.word } }
25
+ let(:block) { -> {} }
23
26
  let(:instance) { instance_double(test_class) }
24
27
  let(:output) { double }
25
28
 
26
29
  before do
27
30
  allow(instance).to receive(method).and_return(output)
28
- if takes_options?
29
- allow(test_class).to receive(:new).with(*arguments, **options).and_return(instance)
30
- else
31
+
32
+ if accepts_block?
33
+ allow(test_class).to receive(:new).with(*arguments, &block).and_return(instance)
34
+ elsif arguments.any?
31
35
  allow(test_class).to receive(:new).with(*arguments).and_return(instance)
36
+ else
37
+ allow(test_class).to receive(:new).with(no_args).and_return(instance)
32
38
  end
33
39
  end
34
40
 
35
41
  it { is_expected.to eq output }
42
+
43
+ it "has matching parameters with initialize" do
44
+ expect(test_class.method(method).parameters).to eq test_class.instance_method(:initialize).parameters
45
+ end
36
46
  end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.shared_examples_for "a versioned spicerack gem" do
4
+ it "has a version number" do
5
+ expect(described_class::VERSION).to be_a String
6
+ expect(described_class::VERSION).not_to be_blank
7
+ expect(described_class::VERSION).to eq Spicerack::VERSION
8
+ end
9
+ end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Rspice
4
4
  # This constant is managed by spicerack
5
- VERSION = "0.4.3"
5
+ VERSION = "0.5.0"
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspice
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Garside
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-10 00:00:00.000000000 Z
11
+ date: 2018-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -57,6 +57,7 @@ files:
57
57
  - lib/rspice/shared_context/with_an_example_descendant_class.rb
58
58
  - lib/rspice/shared_examples.rb
59
59
  - lib/rspice/shared_examples/a_class_pass_method.rb
60
+ - lib/rspice/shared_examples/a_versioned_spicerack_gem.rb
60
61
  - lib/rspice/version.rb
61
62
  homepage: https://www.freshly.com
62
63
  licenses: