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

質問編集履歴

3

追記

2021/12/01 01:31

投稿

TA07
TA07

スコア1

title CHANGED
File without changes
body CHANGED
@@ -33,6 +33,8 @@
33
33
  ### 該当のソースコード
34
34
  `spec/models/user_spec.rb`
35
35
  ```
36
+ require 'rails_helper'
37
+
36
38
  RSpec.describe 'User', type: :model do
37
39
  it"has a valid factory"do
38
40
  expect(FactoryBot.build(:user)).to be_valid

2

追記

2021/12/01 01:31

投稿

TA07
TA07

スコア1

title CHANGED
File without changes
body CHANGED
@@ -8,17 +8,21 @@
8
8
  ### 発生している問題・エラーメッセージ
9
9
 
10
10
  ```
11
+ # bin/rspec spec/models/user_spec.rb
12
+ Running via Spring preloader in process 134
13
+ F
14
+
11
15
  Failures:
12
16
 
13
17
  1) User has a valid factory
14
- Failure/Error: expect(FactoryBot.build(:user)).tobe_valid
18
+ Failure/Error: expect(FactoryBot.build(:user)).to be_valid
15
19
 
16
20
  NameError:
17
21
  uninitialized constant User
18
22
  # ./spec/models/user_spec.rb:5:in `block (2 levels) in <main>'
19
23
  # -e:1:in `<main>'
20
24
 
21
- Finished in 0.05464 seconds (files took 1.12 seconds to load)
25
+ Finished in 0.08281 seconds (files took 1.82 seconds to load)
22
26
  1 example, 1 failure
23
27
 
24
28
  Failed examples:
@@ -31,7 +35,7 @@
31
35
  ```
32
36
  RSpec.describe 'User', type: :model do
33
37
  it"has a valid factory"do
34
- expect(FactoryBot.build(:user)).tobe_valid
38
+ expect(FactoryBot.build(:user)).to be_valid
35
39
  end
36
40
  end
37
41
  ```
@@ -55,19 +59,7 @@
55
59
  require 'rspec/rails'
56
60
  # Add additional requires below this line. Rails is not loaded until this point!
57
61
  require 'capybara/rspec'
58
- # Requires supporting ruby files with custom matchers and macros, etc, in
62
+
59
- # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
60
- # run as spec files by default. This means that files in spec/support that end
61
- # in _spec.rb will both be required and run as specs, causing the specs to be
62
- # run twice. It is recommended that you do not name files matching this glob to
63
- # end with _spec.rb. You can configure this pattern with the --pattern
64
- # option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
65
- #
66
- # The following line is provided for convenience purposes. It has the downside
67
- # of increasing the boot-up time by auto-requiring all files in the support
68
- # directory. Alternatively, in the individual `*_spec.rb` files, manually
69
- # require only the support files necessary.
70
- #
71
63
  Dir[Rails.root.join('spec', 'support', '**', '*.rb')].sort.each { |f| require f }
72
64
 
73
65
  # Checks for pending migrations and applies them before tests are run.
@@ -113,21 +105,6 @@
113
105
  ```
114
106
  `spec/spec_helper.rb`
115
107
  ```
116
- # This file was generated by the `rails generate rspec:install` command. Conventionally, all
117
- # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
118
- # The generated `.rspec` file contains `--require spec_helper` which will cause
119
- # this file to always be loaded, without a need to explicitly require it in any
120
- # files.
121
- #
122
- # Given that it is always loaded, you are encouraged to keep this file as
123
- # light-weight as possible. Requiring heavyweight dependencies from this file
124
- # will add to the boot time of your test suite on EVERY test run, even for an
125
- # individual file that may not need all of that loaded. Instead, consider making
126
- # a separate helper file that requires the additional dependencies and performs
127
- # the additional setup, and require it from the spec files that actually need
128
- # it.
129
- #
130
- # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
131
108
  RSpec.configure do |config|
132
109
  # rspec-expectations config goes here. You can use an alternate
133
110
  # assertion/expectation library such as wrong or the stdlib/minitest
@@ -210,7 +187,74 @@
210
187
  =end
211
188
  end
212
189
  ```
190
+ ### 追記
191
+ `config/application.rb`
192
+ ```
193
+ config.time_zone = 'Tokyo'
194
+ config.generators.test_framework = :rspec
195
+ config.generators.system_tests = false
196
+ config.generators.stylesheets = false
197
+ config.generators.javascripts = false
198
+ config.generators.helper = false
213
199
 
200
+ config.generators do |g|
201
+ g.test_framework :rspec,
202
+ controller_specs: true,
203
+ model_specs: true,
204
+ request_spec: true,
205
+ view_specs: false,
206
+ helper_specs: false,
207
+ routing_specs: false
208
+ end
209
+ ```
210
+ `Gemfile`
211
+ ```
212
+ gem 'rails', '~> 6.1'
213
+ gem 'bootsnap', require: false
214
+ gem 'mysql2', '~> 0.5.3'
215
+ gem 'puma', '~> 5.2.2'
216
+ gem 'sass-rails', '~> 6.0'
217
+ gem 'uglifier', '>= 4.2.0'
218
+
219
+ gem 'jbuilder', '~> 2.11'
220
+
221
+ gem 'solidus', '~> 2.11.0'
222
+ gem 'solidus_auth_devise'
223
+ gem 'solidus_i18n', github: 'solidusio-contrib/solidus_i18n', branch: 'master'
224
+ gem 'paypalhttp', '~> 1.0'
225
+ gem 'solidus_auth_devise'
226
+ gem 'solidus_paypal_commerce_platform'
227
+
228
+ group :development, :test do
229
+ gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
230
+ gem 'rspec-rails'
231
+ gem 'factory_bot_rails'
232
+ gem 'pry-rails'
233
+ gem 'pry-doc'
234
+ gem 'pry-byebug'
235
+ gem 'rails-erd'
236
+ gem 'annotate'
237
+ gem 'rubocop-airbnb'
238
+ gem 'spring-commands-rspec'
239
+ end
240
+
241
+ group :test do
242
+ gem 'capybara'
243
+ gem 'webdrivers'
244
+ gem 'launchy'
245
+ end
246
+
247
+ group :development do
248
+ gem 'web-console', '>= 4.1.0'
249
+ gem 'listen', '>= 3.0.5', '< 4.0'
250
+ gem 'spring'
251
+ gem 'spring-watcher-listen', '~> 2.0.1'
252
+ end
253
+
254
+ gem "aws-sdk", "~> 3.0"
255
+ gem "aws-sdk-s3", require: false
256
+ gem 'ast', '~> 2.4', '>= 2.4.2'
257
+ ```
214
258
  ### 試したこと
215
259
 
216
260
  「uninitialized constant」というエラーから、ファクトリーが定義されてない?FactoryBotに原因があるのではと考え、様々な記事や質問を調べ作り直したりRspec・FactoryBotの設定を見直してみましたが、エラーは変わりませんでした。

1

誤字

2021/12/01 01:17

投稿

TA07
TA07

スコア1

title CHANGED
File without changes
body CHANGED
@@ -27,7 +27,7 @@
27
27
  ```
28
28
 
29
29
  ### 該当のソースコード
30
- `spec/modles/user_spec.rb`
30
+ `spec/models/user_spec.rb`
31
31
  ```
32
32
  RSpec.describe 'User', type: :model do
33
33
  it"has a valid factory"do