質問編集履歴
5
修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -181,6 +181,53 @@
|
|
181
181
|
end
|
182
182
|
end
|
183
183
|
```
|
184
|
+
```
|
185
|
+
FactoryBot.define do
|
186
|
+
|
187
|
+
factory :item do
|
188
|
+
name {"abe"}
|
189
|
+
detail {"aaa"}
|
190
|
+
category_id {"1"}
|
191
|
+
condition {"1"}
|
192
|
+
fee {"1"}
|
193
|
+
prefecture {"aaa"}
|
194
|
+
delivery_date {"1"}
|
195
|
+
price {"111"}
|
196
|
+
end
|
197
|
+
end
|
198
|
+
```
|
199
|
+
**image_spec.rb**
|
200
|
+
```
|
201
|
+
require 'rails_helper'
|
202
|
+
|
203
|
+
describe Image do
|
204
|
+
before do
|
205
|
+
@image = build(:image)
|
206
|
+
end
|
207
|
+
describe "create" do
|
208
|
+
|
209
|
+
it "画像入力されていれば出品できる" do
|
210
|
+
image = FactoryBot.build(:image)
|
211
|
+
expect(image).to be_valid
|
212
|
+
end
|
213
|
+
|
214
|
+
it "商品画像が空では出品できない" do
|
215
|
+
image = FactoryBot.build(:image, image: "")
|
216
|
+
image.valid?
|
217
|
+
expect(image.error(:image)).to include("can`t be blank")
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
221
|
+
```
|
222
|
+
**images.rb**
|
223
|
+
```
|
224
|
+
FactoryBot.define do
|
225
|
+
|
226
|
+
factory :image do
|
227
|
+
image {"aaa.jpg"}
|
228
|
+
end
|
229
|
+
end
|
230
|
+
```
|
184
231
|
**.rspec**
|
185
232
|
```
|
186
233
|
--require spec_helper
|
4
修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
#前提・実現したいこと
|
2
2
|
正直どこを直したらいいのか調べても全く分からない状況です。
|
3
|
+
binding.pryもなぜか効きません。
|
3
4
|
すみませんがわかる方がいらしゃいましたら教えていただけると助かります。
|
4
5
|
よろしくお願い致します。
|
5
6
|
|
3
修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -10,114 +10,104 @@
|
|
10
10
|
DEPRECATION WARNING: #fog_provider is deprecated and has no effect (called from block in <main> at /Users/〇〇/projects/〇〇/config/initializers/carrierwave.rb:7)
|
11
11
|
|
12
12
|
Item
|
13
|
-
|
13
|
+
#create
|
14
|
-
|
14
|
+
商品名、価格、商品説明、カテゴリー、商品状態、配送料の負担、発送元の地域、発送までの日数、が入力されていれば出品できる (FAILED - 1)
|
15
|
-
商品画像が空では出品できない (FAILED - 2)
|
16
|
-
商品名が空では出品できない (FAILED -
|
15
|
+
商品名が空では出品できない (FAILED - 2)
|
17
|
-
商品説明が空では出品できない (FAILED -
|
16
|
+
商品説明が空では出品できない (FAILED - 3)
|
18
|
-
カテゴリーが空では出品できない (FAILED -
|
17
|
+
カテゴリーが空では出品できない (FAILED - 4)
|
19
|
-
商品の状態が空では出品できない (FAILED -
|
18
|
+
商品の状態が空では出品できない (FAILED - 5)
|
20
|
-
配送料の負担が空では出品できない (FAILED -
|
19
|
+
配送料の負担が空では出品できない (FAILED - 6)
|
21
|
-
配送元の地域が空では出品できない (FAILED -
|
20
|
+
配送元の地域が空では出品できない (FAILED - 7)
|
22
|
-
発送までの日数が空では出品できない (FAILED -
|
21
|
+
発送までの日数が空では出品できない (FAILED - 8)
|
23
|
-
価格が空では出品できない (FAILED -
|
22
|
+
価格が空では出品できない (FAILED - 9)
|
24
|
-
価格が数字でない場合(文字列の場合)は、出品できない (FAILED -
|
23
|
+
価格が数字でない場合(文字列の場合)は、出品できない (FAILED - 10)
|
25
24
|
|
26
25
|
Failures:
|
27
26
|
|
28
|
-
1) Item
|
27
|
+
1) Item#create 商品名、価格、商品説明、カテゴリー、商品状態、配送料の負担、発送元の地域、発送までの日数、が入力されていれば出品できる
|
29
|
-
Failure/Error:
|
28
|
+
Failure/Error: item = build(:item)
|
30
29
|
|
31
30
|
NoMethodError:
|
32
|
-
undefined method `build' for #<RSpec::ExampleGroups::Item::
|
31
|
+
undefined method `build' for #<RSpec::ExampleGroups::Item::Create:0x00007fd9b7ca5c18>
|
33
|
-
# ./spec/models/item_spec.rb:
|
32
|
+
# ./spec/models/item_spec.rb:7:in `block (3 levels) in <top (required)>'
|
34
33
|
|
35
|
-
2) Item
|
34
|
+
2) Item#create 商品名が空では出品できない
|
36
|
-
Failure/Error:
|
35
|
+
Failure/Error: item = FactoryBot.build(:item, name: "")
|
37
36
|
|
38
|
-
|
37
|
+
ArgumentError:
|
39
|
-
|
38
|
+
'1' is not a valid condition
|
40
|
-
# ./spec/models/item_spec.rb:
|
39
|
+
# ./spec/models/item_spec.rb:13:in `block (3 levels) in <top (required)>'
|
41
40
|
|
42
|
-
3) Item
|
41
|
+
3) Item#create 商品説明が空では出品できない
|
43
|
-
Failure/Error:
|
42
|
+
Failure/Error: item = FactoryBot.build(:item, detail: "")
|
44
43
|
|
45
|
-
|
44
|
+
ArgumentError:
|
46
|
-
|
45
|
+
'1' is not a valid condition
|
47
|
-
# ./spec/models/item_spec.rb:
|
46
|
+
# ./spec/models/item_spec.rb:20:in `block (3 levels) in <top (required)>'
|
48
47
|
|
49
|
-
4) Item
|
48
|
+
4) Item#create カテゴリーが空では出品できない
|
50
|
-
Failure/Error:
|
49
|
+
Failure/Error: item = FactoryBot.build(:item, category_id: "")
|
51
50
|
|
52
|
-
|
51
|
+
ArgumentError:
|
53
|
-
|
52
|
+
'1' is not a valid condition
|
54
|
-
# ./spec/models/item_spec.rb:
|
53
|
+
# ./spec/models/item_spec.rb:26:in `block (3 levels) in <top (required)>'
|
55
54
|
|
56
|
-
5) Item
|
55
|
+
5) Item#create 商品の状態が空では出品できない
|
57
|
-
Failure/Error:
|
56
|
+
Failure/Error: item = FactoryBot.build(:item, condition: "")
|
58
57
|
|
59
|
-
|
58
|
+
ArgumentError:
|
60
|
-
|
59
|
+
'1' is not a valid fee
|
61
|
-
# ./spec/models/item_spec.rb:
|
60
|
+
# ./spec/models/item_spec.rb:32:in `block (3 levels) in <top (required)>'
|
62
61
|
|
63
|
-
6) Item
|
62
|
+
6) Item#create 配送料の負担が空では出品できない
|
64
|
-
Failure/Error:
|
63
|
+
Failure/Error: item = FactoryBot.build(:item, delivery_fee: "")
|
65
64
|
|
66
|
-
|
65
|
+
ArgumentError:
|
67
|
-
|
66
|
+
'1' is not a valid condition
|
68
|
-
# ./spec/models/item_spec.rb:
|
67
|
+
# ./spec/models/item_spec.rb:38:in `block (3 levels) in <top (required)>'
|
69
68
|
|
70
|
-
7) Item
|
69
|
+
7) Item#create 配送元の地域が空では出品できない
|
71
|
-
Failure/Error:
|
70
|
+
Failure/Error: item = FactoryBot.build(:item, city: "")
|
72
71
|
|
73
|
-
|
72
|
+
ArgumentError:
|
74
|
-
|
73
|
+
'1' is not a valid condition
|
75
|
-
# ./spec/models/item_spec.rb:
|
74
|
+
# ./spec/models/item_spec.rb:44:in `block (3 levels) in <top (required)>'
|
76
75
|
|
77
|
-
8) Item
|
76
|
+
8) Item#create 発送までの日数が空では出品できない
|
78
|
-
Failure/Error:
|
77
|
+
Failure/Error: item = FactoryBot.build(:item, delivery_date: "")
|
79
78
|
|
80
|
-
|
79
|
+
ArgumentError:
|
81
|
-
|
80
|
+
'1' is not a valid condition
|
82
|
-
# ./spec/models/item_spec.rb:
|
81
|
+
# ./spec/models/item_spec.rb:50:in `block (3 levels) in <top (required)>'
|
83
82
|
|
84
|
-
9) Item
|
83
|
+
9) Item#create 価格が空では出品できない
|
85
|
-
Failure/Error:
|
84
|
+
Failure/Error: item = FactoryBot.build(:item, price: "")
|
86
85
|
|
87
|
-
|
86
|
+
ArgumentError:
|
88
|
-
|
87
|
+
'1' is not a valid condition
|
89
|
-
# ./spec/models/item_spec.rb:
|
88
|
+
# ./spec/models/item_spec.rb:56:in `block (3 levels) in <top (required)>'
|
90
89
|
|
91
|
-
10) Item
|
90
|
+
10) Item#create 価格が数字でない場合(文字列の場合)は、出品できない
|
92
|
-
Failure/Error:
|
91
|
+
Failure/Error: item = FactoryBot.build(:item, price: "aaaa")
|
93
92
|
|
94
|
-
|
93
|
+
ArgumentError:
|
95
|
-
|
94
|
+
'1' is not a valid condition
|
96
|
-
# ./spec/models/item_spec.rb:
|
95
|
+
# ./spec/models/item_spec.rb:62:in `block (3 levels) in <top (required)>'
|
97
96
|
|
98
|
-
11) Item valid_create 価格が数字でない場合(文字列の場合)は、出品できない
|
99
|
-
|
97
|
+
Finished in 0.08192 seconds (files took 3.77 seconds to load)
|
100
|
-
|
101
|
-
|
98
|
+
10 examples, 10 failures
|
102
|
-
undefined method `build' for #<RSpec::ExampleGroups::Item::ValidCreate:0x00007faac77fa778>
|
103
|
-
# ./spec/models/item_spec.rb:5:in `block (2 levels) in <top (required)>'
|
104
99
|
|
105
|
-
Finished in 0.0304 seconds (files took 3.46 seconds to load)
|
106
|
-
11 examples, 11 failures
|
107
|
-
|
108
100
|
Failed examples:
|
109
101
|
|
110
|
-
rspec ./spec/models/item_spec.rb:
|
102
|
+
rspec ./spec/models/item_spec.rb:6 # Item#create 商品名、価格、商品説明、カテゴリー、商品状態、配送料の負担、発送元の地域、発送までの日数、が入力されていれば出品できる
|
111
|
-
rspec ./spec/models/item_spec.rb:14 # Item valid_create 商品画像が空では出品できない
|
112
|
-
rspec ./spec/models/item_spec.rb:
|
103
|
+
rspec ./spec/models/item_spec.rb:12 # Item#create 商品名が空では出品できない
|
113
|
-
rspec ./spec/models/item_spec.rb:
|
104
|
+
rspec ./spec/models/item_spec.rb:19 # Item#create 商品説明が空では出品できない
|
114
|
-
rspec ./spec/models/item_spec.rb:
|
105
|
+
rspec ./spec/models/item_spec.rb:25 # Item#create カテゴリーが空では出品できない
|
115
|
-
rspec ./spec/models/item_spec.rb:
|
106
|
+
rspec ./spec/models/item_spec.rb:31 # Item#create 商品の状態が空では出品できない
|
116
|
-
rspec ./spec/models/item_spec.rb:
|
107
|
+
rspec ./spec/models/item_spec.rb:37 # Item#create 配送料の負担が空では出品できない
|
117
|
-
rspec ./spec/models/item_spec.rb:
|
108
|
+
rspec ./spec/models/item_spec.rb:43 # Item#create 配送元の地域が空では出品できない
|
118
|
-
rspec ./spec/models/item_spec.rb:
|
109
|
+
rspec ./spec/models/item_spec.rb:49 # Item#create 発送までの日数が空では出品できない
|
119
|
-
rspec ./spec/models/item_spec.rb:
|
110
|
+
rspec ./spec/models/item_spec.rb:55 # Item#create 価格が空では出品できない
|
120
|
-
rspec ./spec/models/item_spec.rb:68 # Item valid_create 価格が数字でない場合(文字列の場合)は、出品できない
|
121
111
|
```
|
122
112
|
#該当のソースコード
|
123
113
|
**item_spec.rb**
|
2
修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -125,72 +125,65 @@
|
|
125
125
|
require 'rails_helper'
|
126
126
|
|
127
127
|
describe Item do
|
128
|
-
before do
|
129
|
-
@item = build(:item)
|
130
|
-
end
|
131
|
-
describe "
|
128
|
+
describe "#create" do
|
132
129
|
|
133
|
-
it "
|
130
|
+
it "商品名、価格、商品説明、カテゴリー、商品状態、配送料の負担、発送元の地域、発送までの日数、が入力されていれば出品できる" do
|
134
|
-
|
131
|
+
item = build(:item)
|
132
|
+
binding.pry
|
135
|
-
|
133
|
+
expect(item).to be_valid
|
136
134
|
end
|
137
135
|
|
138
|
-
it "商品画像が空では出品できない" do
|
139
|
-
image = build(:image, image: "")
|
140
|
-
image.valid?
|
141
|
-
expect(image.error(:image)).to include("can`t be blank")
|
142
|
-
end
|
143
|
-
|
144
136
|
it "商品名が空では出品できない" do
|
145
|
-
item = build(:item, name: "")
|
137
|
+
item = FactoryBot.build(:item, name: "")
|
146
138
|
item.valid?
|
139
|
+
binding.pry
|
147
140
|
expect(item.errors[:name]).to include("can't be blank")
|
148
141
|
end
|
149
142
|
|
150
143
|
it "商品説明が空では出品できない" do
|
151
|
-
item = build(:item, detail: "")
|
144
|
+
item = FactoryBot.build(:item, detail: "")
|
152
145
|
item.valid?
|
153
146
|
expect(item.errors[:detail]).to include("can't be blank")
|
154
147
|
end
|
155
148
|
|
156
149
|
it "カテゴリーが空では出品できない" do
|
157
|
-
item = build(:item, category_id: "")
|
150
|
+
item = FactoryBot.build(:item, category_id: "")
|
158
151
|
item.valid?
|
159
152
|
expect(item.errors[:category_id]).to include("can't be blank")
|
160
153
|
end
|
161
154
|
|
162
155
|
it "商品の状態が空では出品できない" do
|
163
|
-
item = build(:item,
|
156
|
+
item = FactoryBot.build(:item, condition: "")
|
164
157
|
item.valid?
|
165
|
-
expect(item.errors[:
|
158
|
+
expect(item.errors[:condition]).to include("can't be blank")
|
166
159
|
end
|
167
160
|
|
168
161
|
it "配送料の負担が空では出品できない" do
|
169
|
-
item = build(:item, delivery_fee: "")
|
162
|
+
item = FactoryBot.build(:item, delivery_fee: "")
|
170
163
|
item.valid?
|
171
164
|
expect(item.errors[:delivery_fee]).to include("can't be blank")
|
172
165
|
end
|
173
166
|
|
174
167
|
it "配送元の地域が空では出品できない" do
|
175
|
-
item = build(:item, city: "")
|
168
|
+
item = FactoryBot.build(:item, city: "")
|
176
169
|
item.valid?
|
177
170
|
expect(item.errors[:city]).to include("can't be blank")
|
178
171
|
end
|
179
172
|
|
180
173
|
it "発送までの日数が空では出品できない" do
|
181
|
-
item = build(:item,
|
174
|
+
item = FactoryBot.build(:item, delivery_date: "")
|
182
175
|
item.valid?
|
183
|
-
expect(item.errors[:
|
176
|
+
expect(item.errors[:delivery_date]).to include("can't be blank")
|
184
177
|
end
|
185
178
|
|
186
179
|
it "価格が空では出品できない" do
|
187
|
-
item = build(:item, price: "")
|
180
|
+
item = FactoryBot.build(:item, price: "")
|
188
181
|
item.valid?
|
189
182
|
expect(item.errors[:price]).to include("can't be blank")
|
190
183
|
end
|
191
184
|
|
192
185
|
it "価格が数字でない場合(文字列の場合)は、出品できない" do
|
193
|
-
item = build(:item, price: "aaaa")
|
186
|
+
item = FactoryBot.build(:item, price: "aaaa")
|
194
187
|
item.valid?
|
195
188
|
expect(item.errors[:price]).to include("not a number")
|
196
189
|
end
|
1
修正
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
|
1
|
+
RSpecのテスト bundle exec rspecを実行したらNoMethodError:が出てしまった
|
body
CHANGED
File without changes
|