|
31 | 31 | expect { UseCaseWithMissingPerformMethod.perform }.to raise_error(NotImplementedError) |
32 | 32 | end |
33 | 33 | end |
| 34 | + |
| 35 | + context "with a class containing a constructor with hash arguments" do |
| 36 | + subject(:result){ UseCaseWithConstructorContainingHash.perform(name: "Bert", age: 5) } |
| 37 | + |
| 38 | + it "should have no errors" do |
| 39 | + expect(result.errors.full_messages).to eq([]) |
| 40 | + end |
| 41 | + |
| 42 | + it "should return the use case object" do |
| 43 | + expect(result.class).to eq(UseCaseWithConstructorContainingHash) |
| 44 | + end |
| 45 | + |
| 46 | + it "should have set the name and age" do |
| 47 | + expect(result.age).to eq(5) |
| 48 | + expect(result.name).to eq("Bert") |
| 49 | + end |
| 50 | + end |
| 51 | + |
| 52 | + context "with a class containing a constructor with multiple arguments" do |
| 53 | + subject(:result){ UseCaseWithConstructorContainingStringAndHash.perform("Rocket", height: 50, width: 5) } |
| 54 | + |
| 55 | + it "should have no errors" do |
| 56 | + expect(result.errors.full_messages).to eq([]) |
| 57 | + end |
| 58 | + |
| 59 | + it "should return the use case object" do |
| 60 | + expect(result.class).to eq(UseCaseWithConstructorContainingStringAndHash) |
| 61 | + end |
| 62 | + |
| 63 | + it "should have set the name and age" do |
| 64 | + expect(result.label).to eq("Rocket") |
| 65 | + expect(result.height).to eq(50) |
| 66 | + expect(result.width).to eq(5) |
| 67 | + end |
| 68 | + end |
| 69 | + |
| 70 | + context "with a class containing a constructor with multiple hashes" do |
| 71 | + subject(:result){ UseCaseWithConstructorContainingTwoHashes.perform({label: "Rocket"}, height: 50, width: 5) } |
| 72 | + |
| 73 | + it "should have no errors" do |
| 74 | + expect(result.errors.full_messages).to eq([]) |
| 75 | + end |
| 76 | + |
| 77 | + it "should return the use case object" do |
| 78 | + expect(result.class).to eq(UseCaseWithConstructorContainingTwoHashes) |
| 79 | + end |
| 80 | + |
| 81 | + it "should have set the name and age" do |
| 82 | + expect(result.label).to eq("Rocket") |
| 83 | + expect(result.height).to eq(50) |
| 84 | + expect(result.width).to eq(5) |
| 85 | + end |
| 86 | + end |
34 | 87 | end |
35 | 88 |
|
36 | 89 | context "with a use case that generates errors" do |
@@ -77,6 +130,50 @@ def perform |
77 | 130 | end |
78 | 131 | end |
79 | 132 |
|
| 133 | +class UseCaseWithConstructorContainingHash |
| 134 | + include UseCasePattern |
| 135 | + |
| 136 | + attr_reader :name, :age |
| 137 | + |
| 138 | + def initialize(name:, age:) |
| 139 | + @name = name |
| 140 | + @age = age |
| 141 | + end |
| 142 | + |
| 143 | + def perform |
| 144 | + end |
| 145 | +end |
| 146 | + |
| 147 | +class UseCaseWithConstructorContainingTwoHashes |
| 148 | + include UseCasePattern |
| 149 | + |
| 150 | + attr_reader :label, :height, :width |
| 151 | + |
| 152 | + def initialize(my_hash, height:, width:) |
| 153 | + @label = my_hash[:label] |
| 154 | + @height = height |
| 155 | + @width = width |
| 156 | + end |
| 157 | + |
| 158 | + def perform |
| 159 | + end |
| 160 | +end |
| 161 | + |
| 162 | +class UseCaseWithConstructorContainingStringAndHash |
| 163 | + include UseCasePattern |
| 164 | + |
| 165 | + attr_reader :label, :height, :width |
| 166 | + |
| 167 | + def initialize(label, height:, width:) |
| 168 | + @label = label |
| 169 | + @height = height |
| 170 | + @width = width |
| 171 | + end |
| 172 | + |
| 173 | + def perform |
| 174 | + end |
| 175 | +end |
| 176 | + |
80 | 177 | class UseCaseThatGeneratesErrors |
81 | 178 | include UseCasePattern |
82 | 179 |
|
|
0 commit comments