rspec-arguments 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1a9734a99060988523b68983e2a89a42762fac4a
4
- data.tar.gz: d88e0295ca5d8cf86888638a06ca74fd86d91944
3
+ metadata.gz: 383418f2f244c0de2f9c46c4d22e1c325cf8d28c
4
+ data.tar.gz: 249db8f96b9175a39407740dcfceefd9db94d7d9
5
5
  SHA512:
6
- metadata.gz: cdacb2bb3b9479269e72783743dc1847940af250a7ac3c9abda506ebd2a62696aff6436911afa08536274d96b96e9af36945f04a77499e31301c6930c7cba48d
7
- data.tar.gz: '09655f8595a80ce6880709bfdabb1afc9079993f8ef5a86a19d35931da594ef66d27b372c7641d92cc2cf2ee575f54220ad3f59d458244efd93b81c6f7cd49b7'
6
+ metadata.gz: 1966c9c0c5d385c23100a13d06e01e9b5d12bfbe64e22dcbc2e057cfbf7b03bc4803e5272f613b3e7e5d4b5bf5e470b6204b47a191b80edf380b5573aca71b71
7
+ data.tar.gz: 8b703ff0cca9d0c53ee5859468afa1f372d1dc3198ae57689d18bfa1526512cb2cd97687c26d30e9cfa39bd15d057b21654fa9c9ac11fc35b1c0112982dbc83d
data/README.md CHANGED
@@ -20,10 +20,14 @@ RSpec.describe Thing do
20
20
 
21
21
  it { is_expected.to be_a(Thing) }
22
22
 
23
- describe '#save', :method do
23
+ describe '#perform', :method do
24
24
  method_arg(:save) { true }
25
25
 
26
26
  it { is_expected.to eq(save) }
27
+
28
+ it 'should be able to access the class instance' do
29
+ expect(instance.perform(save: save)).to eq(subject)
30
+ end
27
31
  end
28
32
  end
29
33
  ```
@@ -15,16 +15,17 @@ module RSpec
15
15
  METHOD_KEYWORD_ARG = METHOD_ARG_PREFIX + KEYWORD_ARG_SUFFIX
16
16
  METHOD_BLOCK_ARG = METHOD_ARG_PREFIX + BLOCK_ARG_SUFFIX
17
17
 
18
- def process_subject(clazz)
18
+ def process_subject(clazz, &block)
19
19
  class_method = method_under_test(:class_method)
20
20
 
21
21
  return call_method_with_args(clazz, class_method.to_sym) if class_method
22
22
 
23
- process_instance_subject(clazz)
23
+ process_instance_subject(clazz, &block)
24
24
  end
25
25
 
26
26
  def process_instance_subject(clazz)
27
27
  instance = call_initializer_with_args(clazz)
28
+ yield(instance)
28
29
 
29
30
  method = method_under_test(:method)
30
31
 
@@ -59,6 +59,8 @@ module RSpec
59
59
  private
60
60
 
61
61
  def _arg(positional_arg, keyword_arg, name, position = nil, &block)
62
+ metadata[:rspec_arguments] = true
63
+
62
64
  let(name, &block)
63
65
 
64
66
  if position.is_a?(Integer)
@@ -69,6 +71,8 @@ module RSpec
69
71
  end
70
72
 
71
73
  def _arg_block(block_arg, name, &block)
74
+ metadata[:rspec_arguments] = true
75
+
72
76
  let(name, &block)
73
77
 
74
78
  let(block_arg.+(name.to_s).to_sym) { send(name) }
@@ -12,10 +12,28 @@ module RSpec
12
12
  #
13
13
  def subject
14
14
  __memoized.fetch_or_store(:subject) do
15
- described = described_class || self.class.metadata.fetch(:description_args).first
16
- described.is_a?(Class) ? process_subject(described) : described
15
+ metadata = self.class.metadata
16
+ described = described_class || metadata.fetch(:description_args).first
17
+
18
+ if described.is_a?(Class)
19
+ if metadata[:rspec_arguments] || metadata[:method] || metadata[:class_method]
20
+ process_subject(described) { |instance| __memoized.fetch_or_store(:instance) { instance } }
21
+ else
22
+ described.new
23
+ end
24
+ else
25
+ described
26
+ end
17
27
  end
18
28
  end
29
+
30
+ #
31
+ # Reference to the instantiated object, if testing an instance or instance method (but not class method).
32
+ #
33
+ def instance
34
+ subject # Ensures subject has been loaded
35
+ __memoized.fetch_or_store(:instance) { raise 'Instance is only available when testing class instances or instance methods' }
36
+ end
19
37
  end
20
38
  end
21
39
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RSpec
4
4
  module Arguments
5
- VERSION = '0.2.0'
5
+ VERSION = '0.3.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-arguments
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marco Costa