Last active
December 21, 2017 02:23
-
-
Save amyroi/a7f726308013daa97cdc8bc63888f737 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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