rspec-do_action 0.0.6 → 0.0.7

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
- SHA1:
3
- metadata.gz: 216944392c958422125e44851ce0f58c2cd354fa
4
- data.tar.gz: 9e762829ab6b1434a314d3a13c50d9be9d71d724
2
+ SHA256:
3
+ metadata.gz: dd7110fd7c7b6dc3bce0ea12c8ba747b73af684e3288e0a5f4e392ba1ca75383
4
+ data.tar.gz: dbd38e301b622565e5c949f16fd30a25c650c4bb239dde304acac13c7f77b572
5
5
  SHA512:
6
- metadata.gz: e89cf19dc89d3b8a3c45cbcd20c7cc169bf942ad689597a932df259da1a297f826bdf2a4c169020cd4e474c22f7086c4ccf83e70b568532f2add2570463e1d5a
7
- data.tar.gz: 28aea114cf60b8e05e0ac14a56e859e9b0d71767c8ed85f401f7f7c92ae70beb89c2273b9de56fe20665a8678f2af566727d3db6eaf150df71a2e2983d6015f0
6
+ metadata.gz: 15d9dd5e2496f790186358f746f8531d9ee4ce926d21a45401c6b293bea151e14068e381d7c4770cfdc2cd4a478c6e277083ddfc142dd09b646c714c67ac0ff7
7
+ data.tar.gz: 84ca14fccc1531c582acbfa0b34144c0ddc89ee8dbffcf547aa777493cf276ba03ed43deab381a56cbe3345f22ad4b5462d2a1d51a77f40942d8fcfbdf92bd76
data/README.md CHANGED
@@ -45,6 +45,11 @@ describe "skip auto 'do_action' invoke" do
45
45
 
46
46
  it { expect{ do_action }.to raise_error(RuntimeError) }
47
47
  end
48
+
49
+ describe 'action with metadata', foo: 1 do
50
+ action { |example| expect(example.metadata[:foo]).to eq 1; @result = true }
51
+ it { expect(@result).to eq true }
52
+ end
48
53
  ```
49
54
 
50
55
  ## Contributing
@@ -5,23 +5,26 @@ module Rspec
5
5
  module DoAction
6
6
 
7
7
  module InstanceMethods
8
- def do_action
9
- expect(action).to_not be_nil, "need define action block"
10
- instance_eval &action
8
+ def do_action(*args)
9
+ expect(action_proc).to_not be_nil, "need define action block"
10
+ instance_exec *args, &action_proc
11
11
  end
12
12
 
13
- def auto_do_action_once(force = false)
14
- return if find_variable("@skip_do_action")
15
- return if !force && action.nil?
13
+ def invoke_do_action_once(example, force: false)
14
+ return if !action_proc
15
+ return if !force && skip_do_action?
16
+ return if @do_action_once_invoked
16
17
 
17
- if !@auto_do_action_once
18
- do_action
19
- @auto_do_action_once = true
20
- end
18
+ do_action(example)
19
+ @do_action_once_invoked = true
21
20
  end
22
21
 
23
- def action
24
- find_variable("@action")
22
+ def action_proc
23
+ find_variable("@action_proc")
24
+ end
25
+
26
+ def skip_do_action?
27
+ !!find_variable("@skip_do_action")
25
28
  end
26
29
 
27
30
  def find_variable(name)
@@ -33,13 +36,13 @@ module Rspec
33
36
  module ClassMethods
34
37
  def action(options = {}, &block)
35
38
  @skip_do_action = options[:skip]
36
- @action = block
39
+ @action_proc = block
37
40
  end
38
41
 
39
42
  def do_action(options = {}, &block)
40
43
  @skip_do_action = false
41
44
  action(options, &block) if block
42
- before { auto_do_action_once(true) }
45
+ before { |example| invoke_do_action_once(example, force: true) }
43
46
  end
44
47
 
45
48
  def skip_do_action
@@ -50,9 +53,9 @@ module Rspec
50
53
  end
51
54
 
52
55
  class RSpec::Core::Example
53
- def run_before_example_with_action
56
+ def run_before_example_with_action(*args)
54
57
  run_before_example_without_action
55
- example_group_instance.send(:auto_do_action_once)
58
+ example_group_instance.send(:invoke_do_action_once, self, force: false)
56
59
  end
57
60
 
58
61
  if private_method_defined?(:run_before_example)
@@ -1,5 +1,5 @@
1
1
  module Rspec
2
2
  module DoAction
3
- VERSION = "0.0.6"
3
+ VERSION = "0.0.7"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-do_action
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - sunteya
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-11 00:00:00.000000000 Z
11
+ date: 2019-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -123,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
123
  version: '0'
124
124
  requirements: []
125
125
  rubyforge_project:
126
- rubygems_version: 2.5.2
126
+ rubygems_version: 2.7.6
127
127
  signing_key:
128
128
  specification_version: 4
129
129
  summary: add 'acton' and some useful methods for rspec one-liner syntax.