Sha256: 4008acfbcab0d31716fd8bd10c01b8ad0060d41e97fb12964c5ca110f44de2da

Contents?: true

Size: 1.66 KB

Versions: 3

Compression:

Stored size: 1.66 KB

Contents

module PageMagic
  class Element
    describe Query do
      include_context :webapp_fixture

      let(:page) do
        elements_page = Class.new do
          include PageMagic
          url '/elements'
        end
        elements_page.visit(application: rack_app).current_page
      end

      describe '#execute' do
        context 'no results found' do
          subject do
            QueryBuilder.find(:link).build(css: 'wrong')
          end

          it 'raises an error' do
            expected_message = 'Unable to find css "wrong"'
            expect { subject.execute(page.browser) }.to raise_exception(ElementMissingException, expected_message)
          end
        end

        context 'to many results returned' do
          subject do
            QueryBuilder.find(:link).build(css: 'a')
          end

          it 'raises an error' do
            expected_message = 'Ambiguous match, found 2 elements matching css "a"'
            expect { subject.execute(page.browser) }.to raise_error AmbiguousQueryException, expected_message
          end
        end

        context 'multiple results found' do
          subject do
            QueryBuilder.find(:link).build({ css: 'a' }, {}, multiple_results: true)
          end

          it 'returns an array' do
            result = subject.execute(page.browser)
            expect(result).to be_a(Array)
            expect(result.size).to eq(2)
          end
        end

        it 'returns the result of the capybara query' do
          query = QueryBuilder.find(:link).build(id: 'form_link')
          result = query.execute(page.browser)
          expect(result.text).to eq('link in a form')
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
page_magic-1.2.8 spec/page_magic/element/query_spec.rb
page_magic-1.2.8.alpha spec/page_magic/element/query_spec.rb
page_magic-1.2.7 spec/page_magic/element/query_spec.rb