Sha256: 82dbad61f6c4db4790ee69dfa0d3cd8a12494f2cfa9debf797f11a1431dc3ec0

Contents?: true

Size: 1.6 KB

Versions: 7

Compression:

Stored size: 1.6 KB

Contents

module PageMagic
  describe Watcher do
    describe '#initialize' do
      context 'check has not been called yet' do
        subject do
          described_class.new(:custom_watcher)
        end
        it 'it sets last to nil' do
          expect(subject.last).to be_nil
        end
      end
    end

    describe '#check' do
      context 'method supplied to constructor' do
        subject do
          described_class.new(:object_id)
        end

        it 'assigns last to be the result of calling the method' do
          subject.check(self)
          expect(subject.last).to eq(object_id)
        end
      end
      context 'name and attribute supplied to constructor' do
        subject do
          described_class.new(:my_button, :text)
        end

        it 'assigns last to the value of attribute definined in the constructor' do
          browser_element = double(text: :hello)
          page_element = double(my_button: browser_element)
          expect(subject.check(page_element).last).to eq(:hello)
        end
      end

      context 'block supplied to constructor' do
        def method_on_self(value = nil)
          return @value unless value
          @value = value
        end

        subject do
          described_class.new(:custom_watcher) do
            method_on_self(:called)
            :result
          end
        end

        it 'is called on self' do
          subject.check(self)
          expect(method_on_self).to be(:called)
        end

        it 'assigns last to the resut of the block' do
          expect(subject.check(self).last).to eq(:result)
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
page_magic-1.2.9 spec/watcher_spec.rb
page_magic-1.2.8 spec/watcher_spec.rb
page_magic-1.2.8.alpha spec/watcher_spec.rb
page_magic-1.2.7 spec/watcher_spec.rb
page_magic-1.2.6 spec/watcher_spec.rb
page_magic-1.2.5 spec/watcher_spec.rb
page_magic-1.2.5.alpha1 spec/watcher_spec.rb