teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

5

修正

2020/08/21 09:56

投稿

ntk__7__ksn
ntk__7__ksn

スコア14

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

修正

2020/08/21 09:55

投稿

ntk__7__ksn
ntk__7__ksn

スコア14

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

修正

2020/08/21 09:52

投稿

ntk__7__ksn
ntk__7__ksn

スコア14

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
- valid_create
13
+ #create
14
- 画像、商品名、価格、商品説明、カテゴリー、商品状態、配送料の負担、発送元の地域、発送までの日数、が入力されていれば出品できる (FAILED - 1)
14
+ 商品名、価格、商品説明、カテゴリー、商品状態、配送料の負担、発送元の地域、発送までの日数、が入力されていれば出品できる (FAILED - 1)
15
- 商品画像が空では出品できない (FAILED - 2)
16
- 商品名が空では出品できない (FAILED - 3)
15
+ 商品名が空では出品できない (FAILED - 2)
17
- 商品説明が空では出品できない (FAILED - 4)
16
+ 商品説明が空では出品できない (FAILED - 3)
18
- カテゴリーが空では出品できない (FAILED - 5)
17
+ カテゴリーが空では出品できない (FAILED - 4)
19
- 商品の状態が空では出品できない (FAILED - 6)
18
+ 商品の状態が空では出品できない (FAILED - 5)
20
- 配送料の負担が空では出品できない (FAILED - 7)
19
+ 配送料の負担が空では出品できない (FAILED - 6)
21
- 配送元の地域が空では出品できない (FAILED - 8)
20
+ 配送元の地域が空では出品できない (FAILED - 7)
22
- 発送までの日数が空では出品できない (FAILED - 9)
21
+ 発送までの日数が空では出品できない (FAILED - 8)
23
- 価格が空では出品できない (FAILED - 10)
22
+ 価格が空では出品できない (FAILED - 9)
24
- 価格が数字でない場合(文字列の場合)は、出品できない (FAILED - 11)
23
+ 価格が数字でない場合(文字列の場合)は、出品できない (FAILED - 10)
25
24
 
26
25
  Failures:
27
26
 
28
- 1) Item valid_create 画像、商品名、価格、商品説明、カテゴリー、商品状態、配送料の負担、発送元の地域、発送までの日数、が入力されていれば出品できる
27
+ 1) Item#create 商品名、価格、商品説明、カテゴリー、商品状態、配送料の負担、発送元の地域、発送までの日数、が入力されていれば出品できる
29
- Failure/Error: @item = build(:item)
28
+ Failure/Error: item = build(:item)
30
29
 
31
30
  NoMethodError:
32
- undefined method `build' for #<RSpec::ExampleGroups::Item::ValidCreate:0x00007faac747bc00>
31
+ undefined method `build' for #<RSpec::ExampleGroups::Item::Create:0x00007fd9b7ca5c18>
33
- # ./spec/models/item_spec.rb:5:in `block (2 levels) in <top (required)>'
32
+ # ./spec/models/item_spec.rb:7:in `block (3 levels) in <top (required)>'
34
33
 
35
- 2) Item valid_create 商品画像が空では出品できない
34
+ 2) Item#create 商品が空では出品できない
36
- Failure/Error: @item = build(:item)
35
+ Failure/Error: item = FactoryBot.build(:item, name: "")
37
36
 
38
- NoMethodError:
37
+ ArgumentError:
39
- undefined method `build' for #<RSpec::ExampleGroups::Item::ValidCreate:0x00007faac7687850>
38
+ '1' is not a valid condition
40
- # ./spec/models/item_spec.rb:5:in `block (2 levels) in <top (required)>'
39
+ # ./spec/models/item_spec.rb:13:in `block (3 levels) in <top (required)>'
41
40
 
42
- 3) Item valid_create 商品が空では出品できない
41
+ 3) Item#create 商品説明が空では出品できない
43
- Failure/Error: @item = build(:item)
42
+ Failure/Error: item = FactoryBot.build(:item, detail: "")
44
43
 
45
- NoMethodError:
44
+ ArgumentError:
46
- undefined method `build' for #<RSpec::ExampleGroups::Item::ValidCreate:0x00007faac76b6f60>
45
+ '1' is not a valid condition
47
- # ./spec/models/item_spec.rb:5:in `block (2 levels) in <top (required)>'
46
+ # ./spec/models/item_spec.rb:20:in `block (3 levels) in <top (required)>'
48
47
 
49
- 4) Item valid_create 商品説明が空では出品できない
48
+ 4) Item#create カテゴリーが空では出品できない
50
- Failure/Error: @item = build(:item)
49
+ Failure/Error: item = FactoryBot.build(:item, category_id: "")
51
50
 
52
- NoMethodError:
51
+ ArgumentError:
53
- undefined method `build' for #<RSpec::ExampleGroups::Item::ValidCreate:0x00007faac7722148>
52
+ '1' is not a valid condition
54
- # ./spec/models/item_spec.rb:5:in `block (2 levels) in <top (required)>'
53
+ # ./spec/models/item_spec.rb:26:in `block (3 levels) in <top (required)>'
55
54
 
56
- 5) Item valid_create カテゴリーが空では出品できない
55
+ 5) Item#create 商品の状態が空では出品できない
57
- Failure/Error: @item = build(:item)
56
+ Failure/Error: item = FactoryBot.build(:item, condition: "")
58
57
 
59
- NoMethodError:
58
+ ArgumentError:
60
- undefined method `build' for #<RSpec::ExampleGroups::Item::ValidCreate:0x00007faac77384c0>
59
+ '1' is not a valid fee
61
- # ./spec/models/item_spec.rb:5:in `block (2 levels) in <top (required)>'
60
+ # ./spec/models/item_spec.rb:32:in `block (3 levels) in <top (required)>'
62
61
 
63
- 6) Item valid_create 商品状態が空では出品できない
62
+ 6) Item#create 配送料負担が空では出品できない
64
- Failure/Error: @item = build(:item)
63
+ Failure/Error: item = FactoryBot.build(:item, delivery_fee: "")
65
64
 
66
- NoMethodError:
65
+ ArgumentError:
67
- undefined method `build' for #<RSpec::ExampleGroups::Item::ValidCreate:0x00007faac775af48>
66
+ '1' is not a valid condition
68
- # ./spec/models/item_spec.rb:5:in `block (2 levels) in <top (required)>'
67
+ # ./spec/models/item_spec.rb:38:in `block (3 levels) in <top (required)>'
69
68
 
70
- 7) Item valid_create 配送負担が空では出品できない
69
+ 7) Item#create 配送地域が空では出品できない
71
- Failure/Error: @item = build(:item)
70
+ Failure/Error: item = FactoryBot.build(:item, city: "")
72
71
 
73
- NoMethodError:
72
+ ArgumentError:
74
- undefined method `build' for #<RSpec::ExampleGroups::Item::ValidCreate:0x00007faac776a678>
73
+ '1' is not a valid condition
75
- # ./spec/models/item_spec.rb:5:in `block (2 levels) in <top (required)>'
74
+ # ./spec/models/item_spec.rb:44:in `block (3 levels) in <top (required)>'
76
75
 
77
- 8) Item valid_create 配地域が空では出品できない
76
+ 8) Item#create まで日数が空では出品できない
78
- Failure/Error: @item = build(:item)
77
+ Failure/Error: item = FactoryBot.build(:item, delivery_date: "")
79
78
 
80
- NoMethodError:
79
+ ArgumentError:
81
- undefined method `build' for #<RSpec::ExampleGroups::Item::ValidCreate:0x00007faac778b328>
80
+ '1' is not a valid condition
82
- # ./spec/models/item_spec.rb:5:in `block (2 levels) in <top (required)>'
81
+ # ./spec/models/item_spec.rb:50:in `block (3 levels) in <top (required)>'
83
82
 
84
- 9) Item valid_create 発送までの日数が空では出品できない
83
+ 9) Item#create 価格が空では出品できない
85
- Failure/Error: @item = build(:item)
84
+ Failure/Error: item = FactoryBot.build(:item, price: "")
86
85
 
87
- NoMethodError:
86
+ ArgumentError:
88
- undefined method `build' for #<RSpec::ExampleGroups::Item::ValidCreate:0x00007faac77a9df0>
87
+ '1' is not a valid condition
89
- # ./spec/models/item_spec.rb:5:in `block (2 levels) in <top (required)>'
88
+ # ./spec/models/item_spec.rb:56:in `block (3 levels) in <top (required)>'
90
89
 
91
- 10) Item valid_create 価格がでは出品できない
90
+ 10) Item#create 価格が数字ない場合(文字列の場合)出品できない
92
- Failure/Error: @item = build(:item)
91
+ Failure/Error: item = FactoryBot.build(:item, price: "aaaa")
93
92
 
94
- NoMethodError:
93
+ ArgumentError:
95
- undefined method `build' for #<RSpec::ExampleGroups::Item::ValidCreate:0x00007faac77c6c70>
94
+ '1' is not a valid condition
96
- # ./spec/models/item_spec.rb:5:in `block (2 levels) in <top (required)>'
95
+ # ./spec/models/item_spec.rb:62:in `block (3 levels) in <top (required)>'
97
96
 
98
- 11) Item valid_create 価格が数字でない場合(文字列の場合)は、出品できない
99
- Failure/Error: @item = build(:item)
97
+ Finished in 0.08192 seconds (files took 3.77 seconds to load)
100
-
101
- NoMethodError:
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:9 # Item valid_create 画像、商品名、価格、商品説明、カテゴリー、商品状態、配送料の負担、発送元の地域、発送までの日数、が入力されていれば出品できる
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:20 # Item valid_create 商品名が空では出品できない
103
+ rspec ./spec/models/item_spec.rb:12 # Item#create 商品名が空では出品できない
113
- rspec ./spec/models/item_spec.rb:26 # Item valid_create 商品説明が空では出品できない
104
+ rspec ./spec/models/item_spec.rb:19 # Item#create 商品説明が空では出品できない
114
- rspec ./spec/models/item_spec.rb:32 # Item valid_create カテゴリーが空では出品できない
105
+ rspec ./spec/models/item_spec.rb:25 # Item#create カテゴリーが空では出品できない
115
- rspec ./spec/models/item_spec.rb:38 # Item valid_create 商品の状態が空では出品できない
106
+ rspec ./spec/models/item_spec.rb:31 # Item#create 商品の状態が空では出品できない
116
- rspec ./spec/models/item_spec.rb:44 # Item valid_create 配送料の負担が空では出品できない
107
+ rspec ./spec/models/item_spec.rb:37 # Item#create 配送料の負担が空では出品できない
117
- rspec ./spec/models/item_spec.rb:50 # Item valid_create 配送元の地域が空では出品できない
108
+ rspec ./spec/models/item_spec.rb:43 # Item#create 配送元の地域が空では出品できない
118
- rspec ./spec/models/item_spec.rb:56 # Item valid_create 発送までの日数が空では出品できない
109
+ rspec ./spec/models/item_spec.rb:49 # Item#create 発送までの日数が空では出品できない
119
- rspec ./spec/models/item_spec.rb:62 # Item valid_create 価格が空では出品できない
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

修正

2020/08/21 09:51

投稿

ntk__7__ksn
ntk__7__ksn

スコア14

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 "valid_create" do
128
+ describe "#create" do
132
129
 
133
- it "画像、商品名、価格、商品説明、カテゴリー、商品状態、配送料の負担、発送元の地域、発送までの日数、が入力されていれば出品できる" do
130
+ it "商品名、価格、商品説明、カテゴリー、商品状態、配送料の負担、発送元の地域、発送までの日数、が入力されていれば出品できる" do
134
- item = build(:item)
131
+ item = build(:item)
132
+ binding.pry
135
- expect(item).to be_valid
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, state: "")
156
+ item = FactoryBot.build(:item, condition: "")
164
157
  item.valid?
165
- expect(item.errors[:state]).to include("can't be blank")
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, delivery_days: "")
174
+ item = FactoryBot.build(:item, delivery_date: "")
182
175
  item.valid?
183
- expect(item.errors[:delivery_days]).to include("can't be blank")
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

修正

2020/08/21 09:48

投稿

ntk__7__ksn
ntk__7__ksn

スコア14

title CHANGED
@@ -1,1 +1,1 @@
1
- 単体テスト bundle exec rspecを実行したらNoMethodError:が出てしまった
1
+ RSpecのテスト bundle exec rspecを実行したらNoMethodError:が出てしまった
body CHANGED
File without changes