rest_my_case 1.3.2 → 1.3.5

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
  SHA1:
3
- metadata.gz: f2d0b9d8de92ec372285332d8dce7720f3224323
4
- data.tar.gz: 3bfcd6e611ee75c3ec7ff74cde2246ad80fb2a9e
3
+ metadata.gz: befb7a3cb43ce0e61ec02c2fc33afe9e1d9f734b
4
+ data.tar.gz: 18ac6c5fcf8ddb9a3d8534e7697fd1ae7995d299
5
5
  SHA512:
6
- metadata.gz: a8f3aea034cbf77270ff5a6e9f910959cbd8c536029c66f2b822490947346b1eefea71a960a010f0b8df540d25672bec7cbd61c67aa3caf765d01b94ad2ec745
7
- data.tar.gz: b000730a80b5b848b4890154c5993a26d4d11d52a55c63b5bafb0c8ad22b1c7a65399c62b928fb9771f4132255be863c504d0d3b20fc1b3860f16332dfa2ff83
6
+ metadata.gz: 74deb7063872d6ce4f3a0ed098238b70c27f671f6611ccf291c8facfbe31d5f33f4b18fb368ec04de1b818453c514332422b4e4720fd06d20fa33f90ad6e6529
7
+ data.tar.gz: 57cce6814654046a2a9700952aff2dace3fceb10abb4d804d788facd9263bd9c17a294b802e255c6341e0426085c01efa47f55d21e015c54311de0c62d5357ad
@@ -45,7 +45,7 @@ module RestMyCase
45
45
 
46
46
  def initialize(context, options = {})
47
47
  @context = context
48
- @options = options
48
+ @options = options.dup
49
49
  end
50
50
 
51
51
  def setup; end
@@ -56,14 +56,6 @@ module RestMyCase
56
56
 
57
57
  def final; end
58
58
 
59
- def fail(message = '')
60
- abort && @context.errors[self.class.name].push(message)
61
- end
62
-
63
- def fail!(message = '')
64
- fail(message) && raise(Errors::Abort)
65
- end
66
-
67
59
  def abort
68
60
  options[:should_abort] = true
69
61
  end
@@ -72,6 +64,14 @@ module RestMyCase
72
64
  abort && raise(Errors::Abort)
73
65
  end
74
66
 
67
+ def fail(message = '')
68
+ abort && context.errors[self.class.name].push(message)
69
+ end
70
+
71
+ def fail!(message = '')
72
+ fail(message) && raise(Errors::Abort)
73
+ end
74
+
75
75
  def skip
76
76
  options[:should_skip] = true
77
77
  end
@@ -35,7 +35,7 @@ module RestMyCase
35
35
  def run_rollback_methods
36
36
  return nil unless @use_case_that_aborted
37
37
 
38
- @performed_use_cases.revert.each do |use_case|
38
+ @performed_use_cases.reverse.each do |use_case|
39
39
  run_method(:rollback, use_case)
40
40
  end
41
41
  end
@@ -62,7 +62,7 @@ module RestMyCase
62
62
  begin
63
63
  run_method(method_name, use_case)
64
64
 
65
- use_case.options[:should_abort]
65
+ use_case.options[:should_abort] && @use_case_that_aborted = use_case
66
66
  rescue Errors::Skip => exception
67
67
  false
68
68
  rescue Errors::Abort => exception
@@ -1,5 +1,5 @@
1
1
  module RestMyCase
2
2
 
3
- VERSION = "1.3.2"
3
+ VERSION = "1.3.5"
4
4
 
5
5
  end
@@ -3,15 +3,15 @@ require 'spec_helper'
3
3
  describe RestMyCase::Base do
4
4
 
5
5
  describe ".dependencies" do
6
- it " should only list the class's dependencies" do
6
+ it "should only list the class's dependencies" do
7
7
  expect(RestMyCaseBase::CreatePostWithComments.dependencies).to \
8
8
  eq [RestMyCaseBase::BuildComments, RestMyCaseBase::CreateComments]
9
9
  end
10
10
  end
11
11
 
12
12
  describe ".context_accessor" do
13
- let(:context) { RestMyCase::TrialCase::Context.new(id: 1, comment: 'my comment', session: -1) }
14
- let(:use_case) { RestMyCaseBase::CreatePostWithComments.new(context) }
13
+ let(:context) { RestMyCase::TrialCase::Context.new(id: 1, comment: 'my comment', session: -1) }
14
+ let(:use_case) { RestMyCaseBase::CreatePostWithComments.new(context) }
15
15
 
16
16
  it "Should create getters targeting to context" do
17
17
  expect(use_case.respond_to?(:comment)).to be true
@@ -22,7 +22,7 @@ describe RestMyCase::Base do
22
22
  end
23
23
 
24
24
  it "Getter should delegate to context" do
25
- expect(use_case.comment).to eq context.comment
25
+ expect(use_case.comment).to eq 'my comment'
26
26
  end
27
27
 
28
28
  it "Setter should delegate to context" do
@@ -32,7 +32,8 @@ describe RestMyCase::Base do
32
32
  end
33
33
 
34
34
  describe ".context_writer" do
35
- let(:use_case) { RestMyCaseBase::CreatePostWithComments.new(RestMyCase::TrialCase::Context.new) }
35
+ let(:context) { RestMyCase::TrialCase::Context.new }
36
+ let(:use_case) { RestMyCaseBase::CreatePostWithComments.new(context) }
36
37
 
37
38
  it "Should create setters targeting to context" do
38
39
  expect(use_case.respond_to?(:id)).to be false
@@ -47,8 +48,8 @@ describe RestMyCase::Base do
47
48
  end
48
49
 
49
50
  describe ".context_reader" do
50
- let(:context) { RestMyCase::TrialCase::Context.new(id: 1, comment: 'my comment', session: -1) }
51
- let(:use_case) { RestMyCaseBase::CreatePostWithComments.new(context) }
51
+ let(:context) { RestMyCase::TrialCase::Context.new(id: 1, comment: 'my comment', session: -1) }
52
+ let(:use_case) { RestMyCaseBase::CreatePostWithComments.new(context) }
52
53
 
53
54
  it "Should create getters targeting to context" do
54
55
  expect(use_case.respond_to?(:session)).to be true
@@ -56,21 +57,29 @@ describe RestMyCase::Base do
56
57
  end
57
58
 
58
59
  it "Getter should delegate to context" do
59
- expect(use_case.session).to eq context.session
60
+ expect(use_case.session).to eq -1
60
61
  end
61
62
  end
62
63
 
63
64
  describe ".perform" do
64
65
 
65
- context "When something that doesn't responde to #to_hash is used" do
66
- it "should raise an exception" do
67
- expect { RestMyCaseBase::CreatePost.perform(Object.new) }.to \
68
- raise_error(ArgumentError)
66
+ context "When a use case #fail during the setup process" do
67
+ before do
68
+ class Perform::ValidateName < RestMyCase::Base
69
+ def setup
70
+ fail('no name!')
71
+ context.setup << self.class.name
72
+ end
73
+ end
74
+
75
+ @context = Perform::CreatePost.perform
69
76
  end
70
- end
71
77
 
72
- context "When a use case #abort during the setup process" do
73
- before { @context = Perform::CreatePost.perform }
78
+ after do
79
+ class Perform::ValidateName < RestMyCase::Base
80
+ def setup; context.setup << self.class.name; end
81
+ end
82
+ end
74
83
 
75
84
  it "context should reflect an invalid state" do
76
85
  expect(@context.valid?).to be false
@@ -80,11 +89,74 @@ describe RestMyCase::Base do
80
89
  expect(@context.errors.keys.length).to be 1
81
90
  end
82
91
 
83
- it "context must not be populated by the #perform methods" do
84
- # binding.pry
92
+ it "context prove that only the correct method have ran" do
85
93
  expect(@context.setup.length).to be 2
86
94
  expect(@context.perform.length).to be 0
87
- expect(@context.rollback.length).to be 2
95
+ expect(@context.rollback.length).to be 0
96
+ expect(@context.final.length).to be 6
97
+ end
98
+ end
99
+
100
+ context "When a use case #fail! during the setup process" do
101
+ before do
102
+ class Perform::ValidateName < RestMyCase::Base
103
+ def setup
104
+ fail!('no name!')
105
+ context.setup << self.class.name
106
+ end
107
+ end
108
+
109
+ @context = Perform::CreatePost.perform
110
+ end
111
+
112
+ after do
113
+ class Perform::ValidateName < RestMyCase::Base
114
+ def setup; context.setup << self.class.name; end
115
+ end
116
+ end
117
+
118
+ it "context should reflect an invalid state" do
119
+ expect(@context.valid?).to be false
120
+ end
121
+
122
+ it "context should contain only one error" do
123
+ expect(@context.errors.keys.length).to be 1
124
+ end
125
+
126
+ it "context prove that only the correct method have ran" do
127
+ expect(@context.setup.length).to be 1
128
+ expect(@context.perform.length).to be 0
129
+ expect(@context.rollback.length).to be 0
130
+ expect(@context.final.length).to be 6
131
+ end
132
+ end
133
+
134
+ context "When a use case #skip during the setup process" do
135
+ before do
136
+ class Perform::ValidateBody < RestMyCase::Base
137
+ def setup
138
+ skip
139
+ context.setup << self.class.name
140
+ end
141
+ end
142
+
143
+ @context = Perform::CreatePost.perform
144
+ end
145
+
146
+ after do
147
+ class Perform::ValidateName < RestMyCase::Base
148
+ def setup; context.setup << self.class.name; end
149
+ end
150
+ end
151
+
152
+ it "context should reflect an valid state" do
153
+ expect(@context.valid?).to be true
154
+ end
155
+
156
+ it "context prove that only the correct method have ran" do
157
+ expect(@context.setup.length).to be 6
158
+ expect(@context.perform.length).to be 5
159
+ expect(@context.rollback.length).to be 0
88
160
  expect(@context.final.length).to be 6
89
161
  end
90
162
  end
@@ -1,11 +1,7 @@
1
1
  module Perform
2
2
 
3
3
  class ValidateName < RestMyCase::Base
4
- context_reader :name
5
-
6
4
  def setup
7
- fail('no name present!') if name.nil?
8
-
9
5
  context.setup << self.class.name
10
6
  end
11
7
 
@@ -23,11 +19,7 @@ module Perform
23
19
  end
24
20
 
25
21
  class ValidateBody < RestMyCase::Base
26
- context_reader :body
27
-
28
22
  def setup
29
- fail('no body present!') if body.nil?
30
-
31
23
  context.setup << self.class.name
32
24
  end
33
25
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rest_my_case
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.2
4
+ version: 1.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - goncalvesjoao