質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Cloud9

Cloud9は、クラウドからのプログラミングが可能になるWebサービス。IDEとしての機能が搭載されており、GitHubやHerokuなど他ツールとの連携も可能です。ブラウザ上で動くため、デバイスに関係なく開発環境を準備できます。

Ruby on Rails 5

Ruby on Rails 5は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

RSpec

RSpecはRuby用のBDD(behaviour-driven development)フレームワークです。

Q&A

解決済

1回答

938閲覧

RSpec導入後_bin/rspecを実行するとundefined method `config' for nil:NilClass (NoMethodError)がでる

napoano365

総合スコア28

Cloud9

Cloud9は、クラウドからのプログラミングが可能になるWebサービス。IDEとしての機能が搭載されており、GitHubやHerokuなど他ツールとの連携も可能です。ブラウザ上で動くため、デバイスに関係なく開発環境を準備できます。

Ruby on Rails 5

Ruby on Rails 5は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

RSpec

RSpecはRuby用のBDD(behaviour-driven development)フレームワークです。

0グッド

0クリップ

投稿2019/06/18 08:22

編集2019/06/19 22:45

■困っていること
次のエラーの解決方法がわからずに困っています。
undefined method "config" for nil:NilClass (NoMethodError)

■環境
cloud9
ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux]
Rails 5.2.3

$ sqlite3 -version
3.7.17 2013-05-20 00:56:22 118a3b35693b134d56ebd780123b7fd6f1497668

■これまでにやっていたこと
RSpecをセットアップしたのち $ bin/rspecを実行すると以下のエラーが出ました。

ec2-user:~/environment/InstaClone (develop_0618_RSpec) $ bin/rspec DEPRECATION WARNING: Leaving `ActiveRecord::ConnectionAdapters::SQLite3Adapter.represent_boolean_as_integer` set to false is deprecated. SQLite databases have used 't' and 'f' to serialize boolean values and must have old data converted to 1 and 0 (its native boolean serialization) before setting this flag to true. Conversion can be accomplished by setting up a rake task which runs ExampleModel.where("boolean_column = 't'").update_all(boolean_column: 1) ExampleModel.where("boolean_column = 'f'").update_all(boolean_column: 0) for all models and all boolean columns, after which the flag must be set to true by adding the following to your application.rb file: Rails.application.config.active_record.sqlite3.represent_boolean_as_integer = true (called from instance_eval at /home/ec2-user/environment/InstaClone/vendor/bundler/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/lazy_load_hooks.rb:71) Running via Spring preloader in process 6294 No examples found. Finished in 0.00041 seconds (files took 0.22336 seconds to load) 0 examples, 0 failures

エラーの内容を読むに、"ActiveRecord::ConnectionAdapters::SQLite3Adapter.represent_boolean_as_integerをfalseに設定するのは非推奨です"とのことだったので、
以下のサイトを参考に、application.rbに以下設定を追加してこのフラグをtrueに設定しました。
<参考サイト>
Rails.application.config.active_record.sqlite3.represent_boolean_as_integer = true

すると次のエラーが表示され、対応方法がわからずに悩んでいます。

ec2-user:~/environment/InstaClone (develop_0618_RSpec) $ bin/rspec /home/ec2-user/environment/InstaClone/config/application.rb:10:in `<top (required)>': undefined method `config' for nil:NilClass (NoMethodError) from /home/ec2-user/environment/InstaClone/vendor/bundler/ruby/2.6.0/gems/spring-2.0.2/lib/spring/application.rb:92:in `require' from /home/ec2-user/environment/InstaClone/vendor/bundler/ruby/2.6.0/gems/spring-2.0.2/lib/spring/application.rb:92:in `preload' from /home/ec2-user/environment/InstaClone/vendor/bundler/ruby/2.6.0/gems/spring-2.0.2/lib/spring/application.rb:153:in `serve' from /home/ec2-user/environment/InstaClone/vendor/bundler/ruby/2.6.0/gems/spring-2.0.2/lib/spring/application.rb:141:in `block in run' from /home/ec2-user/environment/InstaClone/vendor/bundler/ruby/2.6.0/gems/spring-2.0.2/lib/spring/application.rb:135:in `loop' from /home/ec2-user/environment/InstaClone/vendor/bundler/ruby/2.6.0/gems/spring-2.0.2/lib/spring/application.rb:135:in `run' from /home/ec2-user/environment/InstaClone/vendor/bundler/ruby/2.6.0/gems/spring-2.0.2/lib/spring/application/boot.rb:19:in `<top (required)>' from /home/ec2-user/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require' from /home/ec2-user/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require' from -e:1:in `<main>'

application.rbの設定方法が間違っているのでしょうか?
詳細をご存じの方、お力添え頂けますと幸いです。
宜しくお願いします。m(_ _)m

[20190620_追記]

application.rb ==== require_relative 'boot' require 'rails/all' # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. Bundler.require(*Rails.groups) #対策:DEPRECATION WARNING: Leaving `ActiveRecord::ConnectionAdapters::SQLite3Adapter.represent_boolean_as_integer`set to false is deprecated. Rails.application.config.active_record.sqlite3.represent_boolean_as_integer = true module InstaClone class Application < Rails::Application # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers # -- all .rb files in that directory are automatically loaded. config.generators do |g| g.test_framework :rspec, fixtures: false, view_specs: false, helper_specs: false, routing_specs: false end end end

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

suama

2019/06/18 23:17

/InstaClone/config/application.rb:10 とエラーメッセージにあるので、おそらく追加された行のところではないでしょうか? 書き方をちょっと間違えているのかな?という気がします。 さしつかえなければapplication.rbを貼って追記いただけるといいと思います。
napoano365

2019/06/19 22:43

suama様 コメントありがとうございます。application.rbの内容は以下の記述となっております。 いかがでしょうか…。 ```application.rb require_relative 'boot' require 'rails/all' # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. Bundler.require(*Rails.groups) #対策:DEPRECATION WARNING: Leaving `ActiveRecord::ConnectionAdapters::SQLite3Adapter.represent_boolean_as_integer`set to false is deprecated. Rails.application.config.active_record.sqlite3.represent_boolean_as_integer = true module InstaClone class Application < Rails::Application # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers # -- all .rb files in that directory are automatically loaded. config.generators do |g| g.test_framework :rspec, fixtures: false, view_specs: false, helper_specs: false, routing_specs: false end end end ```
suama

2019/06/20 00:34

ありがとうございます! 回答いただいているように、設定は、 class Application ....end の中に書くと良いと思います!
guest

回答1

0

ベストアンサー

以下の場所に追加してください。

rb

1module InstaClone 2 class Application < Rails::Application 3 ... 4 config.active_record.sqlite3.represent_boolean_as_integer = true 5 end 6end

投稿2019/06/20 00:19

Mugheart

総合スコア2349

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問