タグ

rubyとmockに関するkatttonのブックマーク (2)

  • calling rspec directly on a model results on errors in stub! method

    When running: rake spec:models everything works well, but when I do rspec spec/models/spot_spec.rb that has Spot.stub! :test1 , I get: undefined method `stub!' for Spot:Class The error happens only when I include that stub! line. Any ideas how to avoid it? I want to run the specs for a specific model only. Update: Using Ruby 1.9.2 and RSpec 2.4.0, here is the spot_spec.rb code: require File.expand

    calling rspec directly on a model results on errors in stub! method
    kattton
    kattton 2013/04/02
    「mockとかstubはbefore(:all)じゃ使えませんから。」
  • webmockとvcrを利用してHTTPのmockを作成する | Act as Professional

    RubyRailsで外部APIを利用するソフトウェアを開発しているときに、テストで実際に何度もAPIに問い合わせにをしていたら、遅くて話になりません。ましてや、外部APIがメンテナンスなんてことになったら、開発が止まってしまいます。 そこで、webmockなどを利用して、HTTPリクエストやレスポンスのmockを作成することが望ましいです。 vcrを組み合わせて利用すれば、初回だけ実際にHTTPリクエストとレスポンスを記録して、2回目以降は記録したデータからmockとしてデータを返すように簡単にできます。 webmockとvcrのインストール方法 Gemfileに以下のように記述する group :development, :test do gem 'webmock' gem 'vcr' end gemをインストールする $ bundle test/test_helper.rbにVCRに

    webmockとvcrを利用してHTTPのmockを作成する | Act as Professional
    kattton
    kattton 2013/02/15
    テストでWebAPIが絡むと遅くなるもんね。ひどく。
  • 1