1
- # encoding: utf-8
2
-
3
1
require 'spec_helper'
4
2
5
3
module Spree
@@ -14,6 +12,8 @@ module Spree
14
12
end
15
13
16
14
context '#variant_price_diff' do
15
+ subject { helper . variant_price ( @variant ) }
16
+
17
17
let ( :product_price ) { 10 }
18
18
let ( :variant_price ) { 10 }
19
19
@@ -25,8 +25,6 @@ module Spree
25
25
allow ( @variant ) . to receive ( :amount_in ) { variant_price }
26
26
end
27
27
28
- subject { helper . variant_price ( @variant ) }
29
-
30
28
context 'when variant is same as master' do
31
29
it { is_expected . to be_nil }
32
30
end
@@ -80,7 +78,7 @@ module Spree
80
78
end
81
79
82
80
context 'when currency is default' do
83
- it 'should return the variant price if the price is different than master' do
81
+ it 'returns the variant price if the price is different than master' do
84
82
product . price = 10
85
83
@variant1 . price = 15
86
84
@variant2 . price = 20
@@ -101,14 +99,14 @@ module Spree
101
99
end
102
100
end
103
101
104
- it 'should return the variant price if the price is different than master' do
102
+ it 'returns the variant price if the price is different than master' do
105
103
product . price = 100
106
104
@variant1 . price = 150
107
105
expect ( helper . variant_price ( @variant1 ) ) . to eq ( '¥150' )
108
106
end
109
107
end
110
108
111
- it 'should be nil when all variant prices are equal' do
109
+ it 'is nil when all variant prices are equal' do
112
110
product . price = 10
113
111
@variant1 . default_price . update_column ( :amount , 10 )
114
112
@variant2 . default_price . update_column ( :amount , 10 )
@@ -142,19 +140,19 @@ module Spree
142
140
end
143
141
144
142
it 'renders a product description without any formatting based on configuration' do
145
- initialDescription = %Q{
143
+ initial_description = %Q{
146
144
<p>hello world</p>
147
145
148
146
<p>tihs is completely awesome and it works</p>
149
147
150
148
<p>why so many spaces in the code. and why some more formatting afterwards?</p>
151
149
}
152
150
153
- product . description = initialDescription
151
+ product . description = initial_description
154
152
155
153
Spree ::Config [ :show_raw_product_description ] = true
156
154
description = product_description ( product )
157
- expect ( description ) . to eq ( initialDescription )
155
+ expect ( description ) . to eq ( initial_description )
158
156
end
159
157
160
158
context 'renders a product description default description incase description is blank' do
@@ -166,43 +164,49 @@ module Spree
166
164
shared_examples_for 'line item descriptions' do
167
165
context 'variant has a blank description' do
168
166
let ( :description ) { nil }
167
+
169
168
it { is_expected . to eq ( Spree . t ( :product_has_no_description ) ) }
170
169
end
171
170
context 'variant has a description' do
172
171
let ( :description ) { 'test_desc' }
172
+
173
173
it { is_expected . to eq ( description ) }
174
174
end
175
175
context 'description has nonbreaking spaces' do
176
176
let ( :description ) { 'test desc' }
177
+
177
178
it { is_expected . to eq ( 'test desc' ) }
178
179
end
179
180
context 'description has line endings' do
180
181
let ( :description ) { "test\n \r \n desc" }
182
+
181
183
it { is_expected . to eq ( 'test desc' ) }
182
184
end
183
185
end
184
186
185
187
context '#line_item_description_text' do
186
188
subject { line_item_description_text description }
187
189
188
- it_should_behave_like 'line item descriptions'
190
+ it_behaves_like 'line item descriptions'
189
191
end
190
192
191
193
context '#cache_key_for_products' do
194
+ subject { helper . cache_key_for_products }
195
+
192
196
let ( :zone ) { Spree ::Zone . new }
193
197
let ( :price_options ) { { tax_zone : zone } }
194
198
195
- subject { helper . cache_key_for_products }
196
- before ( :each ) do
199
+ before do
197
200
@products = double ( 'products collection' )
198
- allow ( helper ) . to receive ( :params ) { { page : 10 } }
201
+ allow ( helper ) . to receive ( :params ) . and_return ( page : 10 )
199
202
allow ( helper ) . to receive ( :current_price_options ) { price_options }
200
203
end
201
204
202
205
context 'when there is a maximum updated date' do
203
206
let ( :updated_at ) { Date . new ( 2011 , 12 , 13 ) }
204
- before :each do
205
- allow ( @products ) . to receive ( :count ) { 5 }
207
+
208
+ before do
209
+ allow ( @products ) . to receive ( :count ) . and_return ( 5 )
206
210
allow ( @products ) . to receive ( :maximum ) . with ( :updated_at ) { updated_at }
207
211
end
208
212
@@ -211,9 +215,10 @@ module Spree
211
215
212
216
context 'when there is no considered maximum updated date' do
213
217
let ( :today ) { Date . new ( 2013 , 12 , 11 ) }
214
- before :each do
215
- allow ( @products ) . to receive ( :count ) { 1_234_567 }
216
- allow ( @products ) . to receive ( :maximum ) . with ( :updated_at ) { nil }
218
+
219
+ before do
220
+ allow ( @products ) . to receive ( :count ) . and_return ( 1_234_567 )
221
+ allow ( @products ) . to receive ( :maximum ) . with ( :updated_at ) . and_return ( nil )
217
222
allow ( Date ) . to receive ( :today ) { today }
218
223
end
219
224
@@ -222,11 +227,11 @@ module Spree
222
227
end
223
228
224
229
context '#cache_key_for_product' do
230
+ subject ( :cache_key ) { helper . cache_key_for_product ( product ) }
231
+
225
232
let ( :product ) { Spree ::Product . new }
226
233
let ( :price_options ) { { tax_zone : zone } }
227
234
228
- subject ( :cache_key ) { helper . cache_key_for_product ( product ) }
229
-
230
235
before do
231
236
allow ( helper ) . to receive ( :current_price_options ) { price_options }
232
237
end
0 commit comments