Skip to content

Instantly share code, notes, and snippets.

@amyroi
Last active December 21, 2017 02:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amyroi/a7f726308013daa97cdc8bc63888f737 to your computer and use it in GitHub Desktop.
Save amyroi/a7f726308013daa97cdc8bc63888f737 to your computer and use it in GitHub Desktop.
# Helper spec内でrequestのmockをする
let(:request) { instance_double("request", methods) }
let(:devices) { %w(android iphone pc) }
let(:methods) {
{}.tap do |t|
devices.map do |device|
t.merge!({ "from_#{device}?": false })
end
end
}
before { allow(helper).to receive(:request).and_return(request) }
# request.from_android? => false
# Helper内で使用しているインスタンス変数にオブジェクトをセットさせる
let(:user) { create(:user) }
helper.instance_variable_set(:@user, user)
# Helper内で呼び出すparamsのスタブ
allow(helper).to receive(:params).and_return( controller: "users/show")
# I18n lazy lookupのstub
expect(helper).to receive(:t).with(".current_page", count: page) { "" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment