page_magic 0.10.0 → 0.11.0.alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.rspec +1 -0
- data/VERSION +1 -1
- data/lib/ext/string.rb +9 -0
- data/lib/page_magic/element.rb +54 -62
- data/lib/page_magic/element_context.rb +4 -4
- data/lib/page_magic/elements.rb +23 -44
- data/lib/page_magic/exceptions.rb +10 -0
- data/lib/page_magic/page_magic.rb +5 -31
- data/lib/page_magic/session.rb +10 -6
- data/lib/page_magic.rb +1 -1
- data/page_magic.gemspec +12 -7
- data/spec/element_context_spec.rb +25 -3
- data/spec/element_spec.rb +96 -21
- data/spec/member_methods_spec.rb +0 -22
- data/spec/{elements_spec.rb → page_magic/elements/elements_spec.rb} +76 -85
- data/spec/page_magic/usage/defining_page_elements_spec.rb +8 -0
- data/spec/page_magic/usage/defining_pages_spec.rb +88 -0
- data/spec/page_magic/usage/include_page_magic_spec.rb +20 -0
- data/spec/page_magic/usage/interacting_with_pages_spec.rb +56 -0
- data/spec/page_magic/usage/starting_a_session_spec.rb +63 -0
- data/spec/spec_helper.rb +35 -2
- metadata +15 -10
- data/lib/page_magic/section.rb +0 -105
- data/spec/page_magic_spec.rb +0 -168
- data/spec/section_spec.rb +0 -106
    
        data/spec/spec_helper.rb
    CHANGED
    
    | @@ -1,16 +1,49 @@ | |
| 1 1 | 
             
            Bundler.require
         | 
| 2 2 | 
             
            $LOAD_PATH.unshift("#{File.dirname(__FILE__)}/lib")
         | 
| 3 3 | 
             
            require 'page_magic'
         | 
| 4 | 
            +
            require 'capybara/rspec'
         | 
| 4 5 | 
             
            require 'helpers/capybara'
         | 
| 5 6 |  | 
| 6 7 | 
             
            RSpec.configure do
         | 
| 7 8 |  | 
| 9 | 
            +
              include Capybara::DSL
         | 
| 10 | 
            +
             | 
| 11 | 
            +
              module PageMagic
         | 
| 12 | 
            +
                class Element
         | 
| 13 | 
            +
                  class << self
         | 
| 14 | 
            +
                    def default_before_hook
         | 
| 15 | 
            +
                      @default_before_hook ||= Proc.new {}
         | 
| 16 | 
            +
                    end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                    def default_after_hook
         | 
| 19 | 
            +
                      @default_after_hook ||= Proc.new {}
         | 
| 20 | 
            +
                    end
         | 
| 21 | 
            +
                  end
         | 
| 22 | 
            +
                  alias_method :initialize_backup, :initialize
         | 
| 23 | 
            +
                  def initialize *args, &block
         | 
| 24 | 
            +
                    @before_hook, @after_hook = self.class.default_before_hook, self.class.default_after_hook
         | 
| 25 | 
            +
                    initialize_backup *args, &block
         | 
| 26 | 
            +
                  end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                  def == page_element
         | 
| 29 | 
            +
                    page_element.is_a?(Element) &&
         | 
| 30 | 
            +
                        @type == page_element.type &&
         | 
| 31 | 
            +
                        @name == page_element.name &&
         | 
| 32 | 
            +
                        @selector == page_element.selector
         | 
| 33 | 
            +
                        @before_hook == page_element.before &&
         | 
| 34 | 
            +
                        @after_hook == page_element.after
         | 
| 35 | 
            +
                  end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                end
         | 
| 38 | 
            +
              end
         | 
| 39 | 
            +
             | 
| 8 40 | 
             
              shared_context :webapp do
         | 
| 9 41 | 
             
                require 'sinatra/base'
         | 
| 10 42 |  | 
| 11 43 | 
             
                rack_app = Class.new(Sinatra::Base) do
         | 
| 12 44 | 
             
                  get '/page1' do
         | 
| 13 | 
            -
             | 
| 45 | 
            +
             | 
| 46 | 
            +
                    "<html><head><title>page1</title></head><body><a href='/page2'>next page</a></body></html>"
         | 
| 14 47 | 
             
                  end
         | 
| 15 48 |  | 
| 16 49 | 
             
                  get '/page2' do
         | 
| @@ -23,7 +56,7 @@ RSpec.configure do | |
| 23 56 | 
             
                      <input type='submit' value='a button'/>
         | 
| 24 57 |  | 
| 25 58 | 
             
                      <div id='form' class="form">
         | 
| 26 | 
            -
                        <a href=' | 
| 59 | 
            +
                        <a id='form_link' href='/page2'>a in a form</a>
         | 
| 27 60 | 
             
                      </form>
         | 
| 28 61 | 
             
                    ELEMENTS
         | 
| 29 62 |  | 
    
        metadata
    CHANGED
    
    | @@ -1,15 +1,15 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: page_magic
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 5 | 
            -
              prerelease: 
         | 
| 4 | 
            +
              version: 0.11.0.alpha
         | 
| 5 | 
            +
              prerelease: 7
         | 
| 6 6 | 
             
            platform: ruby
         | 
| 7 7 | 
             
            authors:
         | 
| 8 8 | 
             
            - Leon Davis
         | 
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date:  | 
| 12 | 
            +
            date: 2014-03-05 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              name: capybara
         | 
| @@ -82,6 +82,7 @@ extensions: [] | |
| 82 82 | 
             
            extra_rdoc_files:
         | 
| 83 83 | 
             
            - README.md
         | 
| 84 84 | 
             
            files:
         | 
| 85 | 
            +
            - .rspec
         | 
| 85 86 | 
             
            - .ruby-gemset
         | 
| 86 87 | 
             
            - .ruby-version
         | 
| 87 88 | 
             
            - .travis.yml
         | 
| @@ -90,24 +91,28 @@ files: | |
| 90 91 | 
             
            - README.md
         | 
| 91 92 | 
             
            - Rakefile
         | 
| 92 93 | 
             
            - VERSION
         | 
| 94 | 
            +
            - lib/ext/string.rb
         | 
| 93 95 | 
             
            - lib/page_magic.rb
         | 
| 94 96 | 
             
            - lib/page_magic/ajax_support.rb
         | 
| 95 97 | 
             
            - lib/page_magic/browser.rb
         | 
| 96 98 | 
             
            - lib/page_magic/element.rb
         | 
| 97 99 | 
             
            - lib/page_magic/element_context.rb
         | 
| 98 100 | 
             
            - lib/page_magic/elements.rb
         | 
| 101 | 
            +
            - lib/page_magic/exceptions.rb
         | 
| 99 102 | 
             
            - lib/page_magic/page_magic.rb
         | 
| 100 | 
            -
            - lib/page_magic/section.rb
         | 
| 101 103 | 
             
            - lib/page_magic/session.rb
         | 
| 102 104 | 
             
            - page_magic.gemspec
         | 
| 103 105 | 
             
            - spec/browser_spec.rb
         | 
| 104 106 | 
             
            - spec/element_context_spec.rb
         | 
| 105 107 | 
             
            - spec/element_spec.rb
         | 
| 106 | 
            -
            - spec/elements_spec.rb
         | 
| 107 108 | 
             
            - spec/helpers/capybara.rb
         | 
| 108 109 | 
             
            - spec/member_methods_spec.rb
         | 
| 109 | 
            -
            - spec/ | 
| 110 | 
            -
            - spec/ | 
| 110 | 
            +
            - spec/page_magic/elements/elements_spec.rb
         | 
| 111 | 
            +
            - spec/page_magic/usage/defining_page_elements_spec.rb
         | 
| 112 | 
            +
            - spec/page_magic/usage/defining_pages_spec.rb
         | 
| 113 | 
            +
            - spec/page_magic/usage/include_page_magic_spec.rb
         | 
| 114 | 
            +
            - spec/page_magic/usage/interacting_with_pages_spec.rb
         | 
| 115 | 
            +
            - spec/page_magic/usage/starting_a_session_spec.rb
         | 
| 111 116 | 
             
            - spec/session_spec.rb
         | 
| 112 117 | 
             
            - spec/spec_helper.rb
         | 
| 113 118 | 
             
            homepage: https://github.com/ladtech/page_magic
         | 
| @@ -125,13 +130,13 @@ required_ruby_version: !ruby/object:Gem::Requirement | |
| 125 130 | 
             
                  version: '0'
         | 
| 126 131 | 
             
                  segments:
         | 
| 127 132 | 
             
                  - 0
         | 
| 128 | 
            -
                  hash:  | 
| 133 | 
            +
                  hash: -2775326310449772104
         | 
| 129 134 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 130 135 | 
             
              none: false
         | 
| 131 136 | 
             
              requirements:
         | 
| 132 | 
            -
              - - ! ' | 
| 137 | 
            +
              - - ! '>'
         | 
| 133 138 | 
             
                - !ruby/object:Gem::Version
         | 
| 134 | 
            -
                  version:  | 
| 139 | 
            +
                  version: 1.3.1
         | 
| 135 140 | 
             
            requirements: []
         | 
| 136 141 | 
             
            rubyforge_project: 
         | 
| 137 142 | 
             
            rubygems_version: 1.8.25
         | 
    
        data/lib/page_magic/section.rb
    DELETED
    
    | @@ -1,105 +0,0 @@ | |
| 1 | 
            -
            module PageMagic
         | 
| 2 | 
            -
              module Section
         | 
| 3 | 
            -
             | 
| 4 | 
            -
                module Location
         | 
| 5 | 
            -
                  def locate_in browser_element, selector
         | 
| 6 | 
            -
                    method, selector = selector.to_a.flatten
         | 
| 7 | 
            -
                    case method
         | 
| 8 | 
            -
                      when :id
         | 
| 9 | 
            -
                        browser_element.find("##{selector}")
         | 
| 10 | 
            -
                      when :css
         | 
| 11 | 
            -
                        browser_element.find(:css, selector)
         | 
| 12 | 
            -
                      when :xpath
         | 
| 13 | 
            -
                        browser_element.find(:xpath, selector)
         | 
| 14 | 
            -
                      else
         | 
| 15 | 
            -
                        raise UnsupportedSelectorException
         | 
| 16 | 
            -
                    end
         | 
| 17 | 
            -
                  end
         | 
| 18 | 
            -
                end
         | 
| 19 | 
            -
                class UndefinedSelectorException < Exception
         | 
| 20 | 
            -
             | 
| 21 | 
            -
                end
         | 
| 22 | 
            -
             | 
| 23 | 
            -
                class << self
         | 
| 24 | 
            -
                  def extended clazz
         | 
| 25 | 
            -
                    clazz.extend(Elements)
         | 
| 26 | 
            -
                    clazz.class_eval do
         | 
| 27 | 
            -
                      attr_reader :name, :selector
         | 
| 28 | 
            -
                      class << self
         | 
| 29 | 
            -
                        def selector selector=nil
         | 
| 30 | 
            -
                          return @selector unless selector
         | 
| 31 | 
            -
             | 
| 32 | 
            -
                          if @parent_browser_element
         | 
| 33 | 
            -
                            @browser_element = locate_in @parent_browser_element, selector
         | 
| 34 | 
            -
                          end
         | 
| 35 | 
            -
             | 
| 36 | 
            -
                          @selector = selector
         | 
| 37 | 
            -
                        end
         | 
| 38 | 
            -
             | 
| 39 | 
            -
                        attr_accessor :parent_browser_element, :browser_element
         | 
| 40 | 
            -
                      end
         | 
| 41 | 
            -
             | 
| 42 | 
            -
                      include Location
         | 
| 43 | 
            -
                      extend Location
         | 
| 44 | 
            -
             | 
| 45 | 
            -
                      def initialize parent_page_element, name=nil, selector=self.class.selector
         | 
| 46 | 
            -
             | 
| 47 | 
            -
                        @selector = selector
         | 
| 48 | 
            -
                        @parent_page_element = parent_page_element
         | 
| 49 | 
            -
             | 
| 50 | 
            -
                        @selector = selector.is_a?(Hash) ? selector : self.class.selector
         | 
| 51 | 
            -
             | 
| 52 | 
            -
                        @browser_element = self.class.browser_element
         | 
| 53 | 
            -
                        raise UndefinedSelectorException, "Pass a selector to the constructor/define one the class" unless @selector || @browser_element
         | 
| 54 | 
            -
             | 
| 55 | 
            -
                        @browser_element = locate_in(@parent_page_element.browser_element, @selector) unless @browser_element
         | 
| 56 | 
            -
                        if name
         | 
| 57 | 
            -
                          @name = name
         | 
| 58 | 
            -
                        else
         | 
| 59 | 
            -
                          @name = underscore(self.class.name).to_sym
         | 
| 60 | 
            -
                        end
         | 
| 61 | 
            -
             | 
| 62 | 
            -
                      end
         | 
| 63 | 
            -
             | 
| 64 | 
            -
             | 
| 65 | 
            -
                      def session
         | 
| 66 | 
            -
                        @parent_page_element.session
         | 
| 67 | 
            -
                      end
         | 
| 68 | 
            -
             | 
| 69 | 
            -
                      # TODO test this
         | 
| 70 | 
            -
                      def locate *args
         | 
| 71 | 
            -
                        @browser_element
         | 
| 72 | 
            -
                      end
         | 
| 73 | 
            -
             | 
| 74 | 
            -
                      #TODO - consolidate this
         | 
| 75 | 
            -
                      def method_missing method, *args
         | 
| 76 | 
            -
                        begin
         | 
| 77 | 
            -
                          ElementContext.new(self, @browser_element, self, *args).send(method, args.first)
         | 
| 78 | 
            -
                        rescue ElementMissingException
         | 
| 79 | 
            -
                          begin
         | 
| 80 | 
            -
                            @browser_element.send(method, *args)
         | 
| 81 | 
            -
                          rescue
         | 
| 82 | 
            -
                            super
         | 
| 83 | 
            -
                          end
         | 
| 84 | 
            -
             | 
| 85 | 
            -
                        end
         | 
| 86 | 
            -
                      end
         | 
| 87 | 
            -
             | 
| 88 | 
            -
                      private
         | 
| 89 | 
            -
             | 
| 90 | 
            -
                      def underscore string
         | 
| 91 | 
            -
                        string.gsub(/::/, '/').
         | 
| 92 | 
            -
                            gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
         | 
| 93 | 
            -
                            gsub(/([a-z\d])([A-Z])/, '\1_\2').
         | 
| 94 | 
            -
                            tr("-", "_").
         | 
| 95 | 
            -
                            downcase
         | 
| 96 | 
            -
                      end
         | 
| 97 | 
            -
             | 
| 98 | 
            -
             | 
| 99 | 
            -
                    end
         | 
| 100 | 
            -
                  end
         | 
| 101 | 
            -
                end
         | 
| 102 | 
            -
             | 
| 103 | 
            -
             | 
| 104 | 
            -
              end
         | 
| 105 | 
            -
            end
         | 
    
        data/spec/page_magic_spec.rb
    DELETED
    
    | @@ -1,168 +0,0 @@ | |
| 1 | 
            -
            require 'spec_helper'
         | 
| 2 | 
            -
            require 'capybara/rspec'
         | 
| 3 | 
            -
            require 'sinatra/base'
         | 
| 4 | 
            -
             | 
| 5 | 
            -
            describe 'page magic' do
         | 
| 6 | 
            -
              include Capybara::DSL
         | 
| 7 | 
            -
             | 
| 8 | 
            -
              describe 'class level' do
         | 
| 9 | 
            -
                let(:app_class) do
         | 
| 10 | 
            -
                  Class.new do
         | 
| 11 | 
            -
                    def call env
         | 
| 12 | 
            -
                      [200, {}, ["hello world!!"]]
         | 
| 13 | 
            -
                    end
         | 
| 14 | 
            -
                  end
         | 
| 15 | 
            -
                end
         | 
| 16 | 
            -
             | 
| 17 | 
            -
                context 'session' do
         | 
| 18 | 
            -
             | 
| 19 | 
            -
                  it 'should setup a session using the specified browser' do
         | 
| 20 | 
            -
                    Capybara::Session.should_receive(:new).with(:chrome, nil).and_return(:chrome_session)
         | 
| 21 | 
            -
             | 
| 22 | 
            -
                    session = PageMagic.session(:chrome)
         | 
| 23 | 
            -
                    Capybara.drivers[:chrome].call(nil).should == Capybara::Selenium::Driver.new(nil, browser: :chrome)
         | 
| 24 | 
            -
             | 
| 25 | 
            -
                    session.browser.should == :chrome_session
         | 
| 26 | 
            -
                  end
         | 
| 27 | 
            -
             | 
| 28 | 
            -
                  it 'should use the Capybara default browser if non is specified' do
         | 
| 29 | 
            -
                    Capybara.default_driver = :rack_test
         | 
| 30 | 
            -
                    session = PageMagic.session
         | 
| 31 | 
            -
                    session.browser.mode.should == :rack_test
         | 
| 32 | 
            -
                  end
         | 
| 33 | 
            -
             | 
| 34 | 
            -
                  it 'should use the supplied Rack application' do
         | 
| 35 | 
            -
                    session = PageMagic.session(application: app_class.new)
         | 
| 36 | 
            -
                    session.browser.visit('/')
         | 
| 37 | 
            -
                    session.browser.text.should == 'hello world!!'
         | 
| 38 | 
            -
                  end
         | 
| 39 | 
            -
             | 
| 40 | 
            -
                  it 'should use the rack app with a given browser' do
         | 
| 41 | 
            -
                    session = PageMagic.session(:rack_test, application: app_class.new)
         | 
| 42 | 
            -
                    session.browser.mode.should == :rack_test
         | 
| 43 | 
            -
                    session.browser.visit('/')
         | 
| 44 | 
            -
                    session.browser.text.should == 'hello world!!'
         | 
| 45 | 
            -
                  end
         | 
| 46 | 
            -
             | 
| 47 | 
            -
                  context 'supported browsers' do
         | 
| 48 | 
            -
                    it 'should support the poltergeist browser' do
         | 
| 49 | 
            -
                      session = PageMagic.session(:poltergeist, application: app_class.new)
         | 
| 50 | 
            -
                      session.browser.driver.is_a?(Capybara::Poltergeist::Driver).should be_true
         | 
| 51 | 
            -
                    end
         | 
| 52 | 
            -
             | 
| 53 | 
            -
                    it 'should support the selenium browser' do
         | 
| 54 | 
            -
                      session = PageMagic.session(:firefox, application: app_class.new)
         | 
| 55 | 
            -
                      session.browser.driver.is_a?(Capybara::Selenium::Driver).should be_true
         | 
| 56 | 
            -
                    end
         | 
| 57 | 
            -
                  end
         | 
| 58 | 
            -
                end
         | 
| 59 | 
            -
              end
         | 
| 60 | 
            -
             | 
| 61 | 
            -
              describe 'instances' do
         | 
| 62 | 
            -
             | 
| 63 | 
            -
                include_context :webapp
         | 
| 64 | 
            -
             | 
| 65 | 
            -
                let(:my_page_class) do
         | 
| 66 | 
            -
                  Class.new do
         | 
| 67 | 
            -
                    include PageMagic
         | 
| 68 | 
            -
                    url '/page1'
         | 
| 69 | 
            -
                    link(:next, :text => "next page")
         | 
| 70 | 
            -
                  end
         | 
| 71 | 
            -
                end
         | 
| 72 | 
            -
             | 
| 73 | 
            -
                let(:another_page_class) do
         | 
| 74 | 
            -
                  Class.new do
         | 
| 75 | 
            -
                    include PageMagic
         | 
| 76 | 
            -
                    url '/another_page1'
         | 
| 77 | 
            -
                  end
         | 
| 78 | 
            -
                end
         | 
| 79 | 
            -
             | 
| 80 | 
            -
                before :each do
         | 
| 81 | 
            -
                  @page = my_page_class.new
         | 
| 82 | 
            -
                end
         | 
| 83 | 
            -
             | 
| 84 | 
            -
             | 
| 85 | 
            -
                describe 'browser integration' do
         | 
| 86 | 
            -
                  it "should use capybara's default session if a one is not supplied" do
         | 
| 87 | 
            -
                    Capybara.default_driver = :rack_test
         | 
| 88 | 
            -
                    my_page_class.new.browser.mode.should == :rack_test
         | 
| 89 | 
            -
                  end
         | 
| 90 | 
            -
                end
         | 
| 91 | 
            -
             | 
| 92 | 
            -
             | 
| 93 | 
            -
                describe 'inheritance' do
         | 
| 94 | 
            -
                  let(:parent_page)  do
         | 
| 95 | 
            -
                    Class.new do
         | 
| 96 | 
            -
                      include PageMagic
         | 
| 97 | 
            -
                      link(:next, :text => "next page")
         | 
| 98 | 
            -
                    end
         | 
| 99 | 
            -
                  end
         | 
| 100 | 
            -
             | 
| 101 | 
            -
                  let(:child_page) do
         | 
| 102 | 
            -
                    Class.new(parent_page)
         | 
| 103 | 
            -
                  end
         | 
| 104 | 
            -
             | 
| 105 | 
            -
                  context 'children' do
         | 
| 106 | 
            -
                    it 'should inherit elements defined on the parent class' do
         | 
| 107 | 
            -
                      child_page.element_definitions.should include(:next)
         | 
| 108 | 
            -
                    end
         | 
| 109 | 
            -
             | 
| 110 | 
            -
                    it 'are added to PageMagic.pages list' do
         | 
| 111 | 
            -
                      PageMagic.pages.should include(child_page)
         | 
| 112 | 
            -
                    end
         | 
| 113 | 
            -
             | 
| 114 | 
            -
                    it 'should pass on element definitions to their children' do
         | 
| 115 | 
            -
                      grand_child_class = Class.new(child_page)
         | 
| 116 | 
            -
                      grand_child_class.element_definitions.should include(:next)
         | 
| 117 | 
            -
                    end
         | 
| 118 | 
            -
                  end
         | 
| 119 | 
            -
                end
         | 
| 120 | 
            -
             | 
| 121 | 
            -
                describe 'visit' do
         | 
| 122 | 
            -
                  it 'should go to the page' do
         | 
| 123 | 
            -
                    @page.visit
         | 
| 124 | 
            -
                    @page.current_path.should == '/page1'
         | 
| 125 | 
            -
                  end
         | 
| 126 | 
            -
                end
         | 
| 127 | 
            -
             | 
| 128 | 
            -
                describe 'text_on_page' do
         | 
| 129 | 
            -
                  it 'should return true' do
         | 
| 130 | 
            -
                    @page.visit
         | 
| 131 | 
            -
                    @page.text_on_page?('next page').should be_true
         | 
| 132 | 
            -
                  end
         | 
| 133 | 
            -
             | 
| 134 | 
            -
                  it 'should return false' do
         | 
| 135 | 
            -
                    @page.visit
         | 
| 136 | 
            -
                    @page.text_on_page?('billy bob').should be_false
         | 
| 137 | 
            -
                  end
         | 
| 138 | 
            -
             | 
| 139 | 
            -
                end
         | 
| 140 | 
            -
             | 
| 141 | 
            -
             | 
| 142 | 
            -
                it 'can have fields' do
         | 
| 143 | 
            -
                  @page.element_definitions[:next].call(@page).should == PageMagic::Element.new(:next, @page, :button, :text => "next")
         | 
| 144 | 
            -
                end
         | 
| 145 | 
            -
             | 
| 146 | 
            -
                it 'should copy fields on to element' do
         | 
| 147 | 
            -
                  new_page = my_page_class.new
         | 
| 148 | 
            -
                  @page.element_definitions[:next].call(@page).should_not equal(new_page.element_definitions[:next].call(new_page))
         | 
| 149 | 
            -
                end
         | 
| 150 | 
            -
             | 
| 151 | 
            -
                it 'gives access to the page text' do
         | 
| 152 | 
            -
                  @page.visit.text.should == 'next page'
         | 
| 153 | 
            -
                end
         | 
| 154 | 
            -
             | 
| 155 | 
            -
                it 'should access a field' do
         | 
| 156 | 
            -
                  @page.visit
         | 
| 157 | 
            -
                  @page.click_next
         | 
| 158 | 
            -
                  @page.text.should == 'page 2 content'
         | 
| 159 | 
            -
                end
         | 
| 160 | 
            -
             | 
| 161 | 
            -
                it 'are registered at class level' do
         | 
| 162 | 
            -
                  PageMagic.instance_variable_set(:@pages, nil)
         | 
| 163 | 
            -
             | 
| 164 | 
            -
                  page = Class.new { include PageMagic }
         | 
| 165 | 
            -
                  PageMagic.pages.should == [page]
         | 
| 166 | 
            -
                end
         | 
| 167 | 
            -
              end
         | 
| 168 | 
            -
            end
         | 
    
        data/spec/section_spec.rb
    DELETED
    
    | @@ -1,106 +0,0 @@ | |
| 1 | 
            -
            require 'spec_helper'
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            describe PageMagic::Section do
         | 
| 4 | 
            -
             | 
| 5 | 
            -
              include_context :webapp
         | 
| 6 | 
            -
             | 
| 7 | 
            -
              before :each do
         | 
| 8 | 
            -
                @elements_page = elements_page.new
         | 
| 9 | 
            -
                @elements_page.visit
         | 
| 10 | 
            -
              end
         | 
| 11 | 
            -
             | 
| 12 | 
            -
              let!(:elements_page) do
         | 
| 13 | 
            -
             | 
| 14 | 
            -
                Class.new do
         | 
| 15 | 
            -
                  include PageMagic
         | 
| 16 | 
            -
                  url '/elements'
         | 
| 17 | 
            -
                  section :form_by_css do
         | 
| 18 | 
            -
                    selector css: '.form'
         | 
| 19 | 
            -
                    link(:link_in_form, text: 'a in a form')
         | 
| 20 | 
            -
                  end
         | 
| 21 | 
            -
             | 
| 22 | 
            -
                  section :form_by_id do
         | 
| 23 | 
            -
                    selector id: 'form'
         | 
| 24 | 
            -
                    link(:link_in_form, text: 'a in a form')
         | 
| 25 | 
            -
                  end
         | 
| 26 | 
            -
                end
         | 
| 27 | 
            -
              end
         | 
| 28 | 
            -
             | 
| 29 | 
            -
              context 'class level' do
         | 
| 30 | 
            -
                let(:section) do
         | 
| 31 | 
            -
                  Class.new do
         | 
| 32 | 
            -
                    extend PageMagic::Section
         | 
| 33 | 
            -
                  end
         | 
| 34 | 
            -
                end
         | 
| 35 | 
            -
             | 
| 36 | 
            -
                describe 'selector' do
         | 
| 37 | 
            -
                  before do
         | 
| 38 | 
            -
                    section.parent_browser_element = @elements_page.browser
         | 
| 39 | 
            -
                  end
         | 
| 40 | 
            -
             | 
| 41 | 
            -
                  it 'should find by id' do
         | 
| 42 | 
            -
                    section.selector id: 'form'
         | 
| 43 | 
            -
                    section.browser_element[:id].should == 'form'
         | 
| 44 | 
            -
                  end
         | 
| 45 | 
            -
             | 
| 46 | 
            -
                  it 'should find by css' do
         | 
| 47 | 
            -
                    section.selector css: '.form'
         | 
| 48 | 
            -
                    section.browser_element[:id].should == 'form'
         | 
| 49 | 
            -
                  end
         | 
| 50 | 
            -
             | 
| 51 | 
            -
                  it 'should find by xpath' do
         | 
| 52 | 
            -
                    section.selector xpath: '//div'
         | 
| 53 | 
            -
                    section.browser_element[:id].should == 'form'
         | 
| 54 | 
            -
                  end
         | 
| 55 | 
            -
                end
         | 
| 56 | 
            -
              end
         | 
| 57 | 
            -
             | 
| 58 | 
            -
              describe 'method_missing' do
         | 
| 59 | 
            -
                it 'should delegate to capybara' do
         | 
| 60 | 
            -
                  @elements_page.form_by_css.visible?.should be(true)
         | 
| 61 | 
            -
                end
         | 
| 62 | 
            -
             | 
| 63 | 
            -
                it 'should throw default exception if the method does not exist on the capybara object' do
         | 
| 64 | 
            -
                  expect { @elements_page.form_by_css.bobbins }.to raise_exception NoMethodError
         | 
| 65 | 
            -
                end
         | 
| 66 | 
            -
              end
         | 
| 67 | 
            -
             | 
| 68 | 
            -
              it 'can have elements' do
         | 
| 69 | 
            -
                @elements_page.form_by_css.link_in_form.visible?.should be_true
         | 
| 70 | 
            -
              end
         | 
| 71 | 
            -
             | 
| 72 | 
            -
             | 
| 73 | 
            -
              describe 'construction' do
         | 
| 74 | 
            -
             | 
| 75 | 
            -
                let(:page_section_class) do
         | 
| 76 | 
            -
                  page_section_class = Class.new do
         | 
| 77 | 
            -
                    extend PageMagic::Section
         | 
| 78 | 
            -
                  end
         | 
| 79 | 
            -
                  page_section_class.stub(:name).and_return('PageSection')
         | 
| 80 | 
            -
                  page_section_class
         | 
| 81 | 
            -
                end
         | 
| 82 | 
            -
             | 
| 83 | 
            -
                let(:selector) { {css: '.class_name'} }
         | 
| 84 | 
            -
             | 
| 85 | 
            -
                let!(:browser) { double('browser', find: :browser_element) }
         | 
| 86 | 
            -
                let!(:parent_page_element){ double('parent_page_element', browser_element: browser)}
         | 
| 87 | 
            -
             | 
| 88 | 
            -
                context 'selector' do
         | 
| 89 | 
            -
                  it 'should use the class defined selector if one is not given to the constructor' do
         | 
| 90 | 
            -
                    page_section_class.selector selector
         | 
| 91 | 
            -
                    page_section_class.new(parent_page_element).selector.should == selector
         | 
| 92 | 
            -
                  end
         | 
| 93 | 
            -
             | 
| 94 | 
            -
                  it 'should raise an error if a class selector is not defined and one is not given to the constructor' do
         | 
| 95 | 
            -
                    expect { page_section_class.new(parent_page_element) }.to raise_error(PageMagic::Section::UndefinedSelectorException)
         | 
| 96 | 
            -
                  end
         | 
| 97 | 
            -
                end
         | 
| 98 | 
            -
             | 
| 99 | 
            -
                context 'name' do
         | 
| 100 | 
            -
                  it 'should default to the name of the class if one is not supplied' do
         | 
| 101 | 
            -
                    page_section_class.selector selector
         | 
| 102 | 
            -
                    page_section_class.new(parent_page_element).name.should == :page_section
         | 
| 103 | 
            -
                  end
         | 
| 104 | 
            -
                end
         | 
| 105 | 
            -
              end
         | 
| 106 | 
            -
            end
         |