Help us understand the problem. What is going on with this article?

shoulda-matchers 2.8.0で undefined method `validate_presence_of'などと出たので。

More than 5 years have passed since last update.
  • Rails 4.2.0
  • Rspec 3.2.2
  • shoulda-matchers 2.8.0
it { should validate_presence_of(:hoge) }
it { should validate_uniqueness_of(:hage) }

とかでundefined methodだと怒られました。調べてみると・・・

[https://github.com/thoughtbot/shoulda/issues/203:embed:cite]

ちょっとバージョンが古いのですが、その他のコメントを見ると

[https://github.com/thoughtbot/shoulda/issues/203#issuecomment-73694540]

Having the same error with rails '4.2.0' & shoulda-matchers 2.8.0 & rspec-rails 3.1.0

新しくても問題は起こっているようです。

spec_helperrequire 'shoulda/matcherを追加しろとか(ハイフンでなくてスラッシュであるのがポイントかな?)

いろいろあるんですが、結局

[https://github.com/thoughtbot/shoulda/issues/203#issuecomment-42126779]

It seems that reverting shoulda-matcher back to version 2.5.0 fix this.

これがめんどくさくなくていいかな、と思いバージョンを2.5.0に指定して入れ直しましたよと・・・。

Gemfile

.
.
group :test do
  gem 'capybara'
  gem 'faker'
  gem 'shoulda-matchers', '2.5.0'
end
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away