Sha256: 76bd3fb13b063a71dd442811265fae50040b2846f7d8d19b6c449f8c2d4c0a8c

Contents?: true

Size: 1.82 KB

Versions: 21

Compression:

Stored size: 1.82 KB

Contents

require 'spec_helper'

describe Honeydew::Device do
  let(:response) { '{"success": true }' }
  let(:device)   { Honeydew::Device.new('ABC123DEF') }
  let(:device_end_point) do
    "http://127.0.0.1:#{device.port}"
  end

  before do
    Net::HTTP.stub(:post_form).and_return(response)
  end

  describe '#contains_textview_text?' do
    let(:text)     { 'Ok' }
    let(:command)  do
      {'action' => 'is_text_present',
       'arguments' => {'text' => text, 'type' => 'TextView'}}
    end

    it 'should make the call with command is_text_present' do
      Net::HTTP.should_receive(:post_form).with(device_end_point, params: {'command' => command})
      device.contains_textview_text?(text)
    end

    context 'on successful response' do
      let(:response) { '{ "success": true }' }

      it 'should return true' do
        device.contains_textview_text?(text).should be_true
      end
    end

    context 'on failure response' do
      let(:response) { '{ "success": false }' }

      it 'should return false' do
        device.contains_textview_text?(text).should be_false
      end
    end
  end

  describe '#contains_button?' do
    let(:text)     { 'Ok' }
    let(:command)  { {'action' => 'is_button_present', 'arguments' => {'text' => text}} }

    it 'should make the call with command is_button_present' do
      Net::HTTP.should_receive(:post_form).with(device_end_point, params: {'command' => command})
      device.contains_button?(text)
    end

    context 'on successful response' do
      let(:response) { '{ "success": true }' }

      it 'should return true' do
        device.contains_button?(text).should be_true
      end
    end

    context 'on failure response' do
      let(:response) { '{ "success": false }' }

      it 'should return false' do
        device.contains_button?(text).should be_false
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
honeydew-0.14.0 spec/honeydew/device_spec.rb