Skip to content

Commit

Permalink
remove usages of instance variables
Browse files Browse the repository at this point in the history
  • Loading branch information
YusukeIwaki committed Jul 19, 2020
1 parent 26ee0b2 commit 46fcf0b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
6 changes: 3 additions & 3 deletions spec/integration/browser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
RSpec.describe Puppeteer::Browser, puppeteer: :browser do
describe 'version' do
it 'should indicate we are in headless' do
expect(@browser.version).to start_with('Headless')
expect(browser.version).to start_with('Headless')
end
end

describe 'user_agent' do
it 'should include WebKit' do
expect(@browser.user_agent).to include('WebKit')
expect(browser.user_agent).to include('WebKit')
end
end

describe 'target' do
it 'should return browser target' do
expect(@browser.target.type).to eq('browser')
expect(browser.target.type).to eq('browser')
end
end
end
15 changes: 13 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
config.around(:each, type: :puppeteer) do |example|
if example.metadata[:puppeteer].to_s == 'browser'
Puppeteer.launch do |browser|
@browser = browser
@puppeteer_browser = browser
example.run
end
else
Puppeteer.launch do |browser|
@page = browser.pages.first || browser.new_page
@puppeteer_page = browser.pages.first || browser.new_page
example.run
end
end
Expand All @@ -29,4 +29,15 @@
config.define_derived_metadata(file_path: %r(/spec/integration/)) do |metadata|
metadata[:type] = :puppeteer
end

module PuppeteerMethods
def browser
@puppeteer_browser or raise NoMethodError.new('undefined method "browser" (If you intended to use puppeteer#browser, you have to add `puppeteer: :browser` to metadata.)')
end

def page
@puppeteer_page or raise NoMethodError.new('undefined method "page"')
end
end
config.include PuppeteerMethods, type: :puppeteer
end

0 comments on commit 46fcf0b

Please sign in to comment.