|
3 | 3 |
|
4 | 4 | RSpec.describe LightService::Context do
|
5 | 5 | let(:context) { LightService::Context.make }
|
| 6 | + let(:adapter_double) { instance_double("LightService::LocalizationAdapter") } |
6 | 7 |
|
7 | 8 | describe "can be made" do
|
8 | 9 | context "with no arguments" do
|
|
98 | 99 | expect(context.error_code).to eq(10_005)
|
99 | 100 | end
|
100 | 101 |
|
101 |
| - it "uses localization adapter to translate failure message" do |
102 |
| - action_class = TestDoubles::AnAction |
103 |
| - expect(LightService::Configuration.localization_adapter) |
104 |
| - .to receive(:failure) |
105 |
| - .with(:failure_reason, action_class, {}) |
106 |
| - .and_return("message") |
| 102 | + context "when I18n is defined" do |
| 103 | + it "uses localization adapter to translate failure message" do |
| 104 | + action_class = TestDoubles::AnAction |
| 105 | + expect(LightService::Configuration.localization_adapter) |
| 106 | + .to receive(:failure) |
| 107 | + .with(:failure_reason, action_class, {}) |
| 108 | + .and_return("message") |
107 | 109 |
|
108 |
| - context = LightService::Context.make |
109 |
| - context.current_action = action_class |
110 |
| - context.fail!(:failure_reason) |
| 110 | + context = LightService::Context.make |
| 111 | + context.current_action = action_class |
| 112 | + context.fail!(:failure_reason) |
111 | 113 |
|
112 |
| - expect(context).to be_failure |
113 |
| - expect(context.message).to eq("message") |
| 114 | + expect(context).to be_failure |
| 115 | + expect(context.message).to eq("message") |
| 116 | + end |
| 117 | + |
| 118 | + it "uses localization adapter to translate success message" do |
| 119 | + action_class = TestDoubles::AnAction |
| 120 | + expect(LightService::Configuration.localization_adapter) |
| 121 | + .to receive(:success) |
| 122 | + .with(:action_passed, action_class, {}) |
| 123 | + .and_return("message") |
| 124 | + |
| 125 | + context = LightService::Context.make |
| 126 | + context.current_action = action_class |
| 127 | + context.succeed!(:action_passed) |
| 128 | + |
| 129 | + expect(context).to be_success |
| 130 | + expect(context.message).to eq("message") |
| 131 | + end |
114 | 132 | end
|
115 | 133 |
|
116 |
| - it "uses localization adapter to translate success message" do |
117 |
| - action_class = TestDoubles::AnAction |
118 |
| - expect(LightService::Configuration.localization_adapter) |
119 |
| - .to receive(:success) |
120 |
| - .with(:action_passed, action_class, {}) |
121 |
| - .and_return("message") |
| 134 | + context "when I18n is not defined" do |
| 135 | + before do |
| 136 | + allow(LightService::Configuration) |
| 137 | + .to receive(:localization_adapter) |
| 138 | + .and_return(adapter_double) |
| 139 | + end |
| 140 | + |
| 141 | + it "uses localization adapter to translate failure message" do |
| 142 | + action_class = TestDoubles::AnAction |
| 143 | + expect(LightService::Configuration.localization_adapter) |
| 144 | + .to receive(:failure) |
| 145 | + .with(:failure_reason, TestDoubles::AnAction, {}) |
| 146 | + .and_return("message") |
122 | 147 |
|
123 |
| - context = LightService::Context.make |
124 |
| - context.current_action = action_class |
125 |
| - context.succeed!(:action_passed) |
| 148 | + context = LightService::Context.make |
| 149 | + context.current_action = action_class |
| 150 | + context.fail!(:failure_reason) |
126 | 151 |
|
127 |
| - expect(context).to be_success |
128 |
| - expect(context.message).to eq("message") |
| 152 | + expect(context).to be_failure |
| 153 | + expect(context.message).to eq("message") |
| 154 | + end |
| 155 | + |
| 156 | + it "uses localization adapter to translate success message" do |
| 157 | + action_class = TestDoubles::AnAction |
| 158 | + expect(LightService::Configuration.localization_adapter) |
| 159 | + .to receive(:success) |
| 160 | + .with(:action_passed, action_class, {}) |
| 161 | + .and_return("message") |
| 162 | + |
| 163 | + context = LightService::Context.make |
| 164 | + context.current_action = action_class |
| 165 | + context.succeed!(:action_passed) |
| 166 | + |
| 167 | + expect(context).to be_success |
| 168 | + expect(context.message).to eq("message") |
| 169 | + end |
129 | 170 | end
|
130 | 171 |
|
131 | 172 | it "can set a flag to skip all subsequent actions" do
|
|
0 commit comments