Sha256: 62f0746c13798e2daf01b9e7931d391a848d6c79afa2312a1a3bd63c950c8fc1

Contents?: true

Size: 1.95 KB

Versions: 6

Compression:

Stored size: 1.95 KB

Contents

Bundler.require
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/lib")
if ENV['coverage']
  require 'simplecov'
  SimpleCov.start do
    add_filter '/spec/'
  end
end
require 'page_magic'
require 'capybara/rspec'
require 'helpers/capybara'

shared_context :files do
  require 'tmpdir'
  def scratch_dir
    @dir ||= Dir.mktmpdir
  end
end

shared_context :rack_application do
  let(:rack_application) do
    Class.new do
      def call(_env)
        [200, {}, ['hello world!!']]
      end
    end
  end
end

RSpec.configure do
  module PageMagic
    class Element
      class << self
        def default_before_hook
          @default_before_hook ||= proc {}
        end

        def default_after_hook
          @default_after_hook ||= proc {}
        end
      end
      alias_method :initialize_backup, :initialize
      def initialize(*args, &block)
        initialize_backup *args, &block
        @before_hook = self.class.default_before_hook
        @after_hook = self.class.default_after_hook
      end

      def ==(page_element)
        page_element.is_a?(Element) &&
          @type == page_element.type &&
          @name == page_element.name &&
          @selector == page_element.selector
        @before_hook == page_element.before &&
          @after_hook == page_element.after
      end
    end
  end

  shared_context :webapp do
    require 'sinatra/base'

    rack_app = Class.new(Sinatra::Base) do
      get '/page1' do
        "<html><head><title>page1</title></head><body><a href='/page2'>next page</a></body></html>"
      end

      get '/page2' do
        'page 2 content'
      end

      get '/elements' do
        <<-ELEMENTS
          <a href='#'>a link</a>
          <input type='submit' value='a button'/>

          <div id='form' class="form">
            <a id='form_link' href='/page2'>a in a form</a>
          </form>
        ELEMENTS
      end
    end

    before :each do
      Capybara.app = rack_app
    end

    after do
      Capybara.reset!
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
page_magic-1.0.0.alpha10 spec/spec_helper.rb
page_magic-1.0.0.alpha9 spec/spec_helper.rb
page_magic-1.0.0.alpha8 spec/spec_helper.rb
page_magic-1.0.0.alpha7 spec/spec_helper.rb
page_magic-1.0.0.alpha6 spec/spec_helper.rb
page_magic-1.0.0.alpha5 spec/spec_helper.rb