LoginSignup
1
0

Gemfile: Undefined local variable or methodエラーの解決

Posted at

bundlerを使用してgemをインストールしようとしたところエラーが発生したので原因調査を行い解決したプロセスをまとめていきます。

背景

rspecの学習をするために、Gemfileにrspecを追加してbundle installした際にエラーが発生しました。

発生したエラー

[!] There was an error parsing `Gemfile`: Undefined local variable or method `rspec' for Gemfile. Bundler cannot continue.

 #  from /Users/xxx/Documents/ruby/Gemfile:7
 #  -------------------------------------------
 #  
 >  gem rspec
 #  -------------------------------------------

原因

Undefined local variable or methodというエラーメッセージなのでrspecが変数かメソッドとして認識されていることが原因でした。

解決

以下のようにクオーテーションで囲んで、rspecを文字列として認識させました。

# frozen_string_literal: true

source "https://rubygems.org"

# gem "rails"

gem rspec

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0