Sha256: 47de56d8c28541a470a6c2cd38eb1d12b199a368960c1680bb7e57fd30a9c828

Contents?: true

Size: 1.05 KB

Versions: 4

Compression:

Stored size: 1.05 KB

Contents

#
# This file is part of the brauser gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
# Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
#

require "spec_helper"

describe Brauser::Hooks::RubyOnRails do
  before(:each) do
    stub_const("ActionController::Base", ::Class.new)
    allow(::ActionController::Base).to receive(:helper_method)
    allow_any_instance_of(::ActionController::Base).to receive(:request).and_return(::OpenStruct.new(headers: {}))
    ::ActionController::Base.send(:include, ::Brauser::Hooks::RubyOnRails)
  end

  let(:controller){::ActionController::Base.new}

  it "should append to ActionController::Base" do
    expect(controller.respond_to?(:browser)).to be_truthy
  end

  it "should memoize browser" do
    browser = controller.browser
    expect(browser).to be_a(::Brauser::Browser)
    expect(controller.browser).to eq(browser)
  end

  it "should detect browser again" do
    browser = controller.browser
    expect(controller.browser(true)).not_to eq(browser)
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
brauser-4.1.2 spec/brauser/hooks_spec.rb
brauser-4.1.1 spec/brauser/hooks_spec.rb
brauser-4.1.0 spec/brauser/hooks_spec.rb
brauser-4.0.0 spec/brauser/hooks_spec.rb