Sha256: 6f395c7a6631253f56012e5999c5ad06af0f99004b43167841df488d230f5178

Contents?: true

Size: 1.82 KB

Versions: 12

Compression:

Stored size: 1.82 KB

Contents

require_relative 'test_helper.rb'

class HelperForTesting
  include Frank::Cucumber::KeyboardHelper


  def mock_frank_server
    RR.mock(@mock_frank_server = Object.new)
  end

  private
  def frank_server
    @mock_frank_server
  end
end

describe "frank keyboard helper" do
  
  the_helper = nil
  before do
    the_helper = HelperForTesting.new
  end

  def successful_response
    %Q{ { "outcome": "SUCCESS" } }
  end

  it 'posts to the right endpoint' do
    the_helper.mock_frank_server.send_post('type_into_keyboard', anything ){ successful_response }

    the_helper.type_into_keyboard('blah')
  end

  it 'sends the right payload, adding a trailing new-line if needed' do
    the_helper.mock_frank_server.send_post.with_any_args do |endpoint,payload|
      payload.must_equal( {:text_to_type => "the text I want to type\n"} )

      successful_response
    end

    the_helper.type_into_keyboard('the text I want to type')
  end

  it "doesn't add a trailing newline if already there" do
    the_helper.mock_frank_server.send_post.with_any_args do |endpoint,payload|
      payload.must_equal( {:text_to_type => "existing newline\n"} )

      successful_response
    end

    the_helper.type_into_keyboard("existing newline\n")
  end

  it 'raises an exception if the server responds negatively' do
    failure_message = <<-EOS
    { 
      "outcome": "NOT SUCCESS AT ALL",
      "reason": "reason for failure",
      "details": "details about failure"
    }
    EOS

    the_helper.mock_frank_server.send_post.with_any_args{ failure_message }

    exception = lambda{ 
      the_helper.type_into_keyboard('text we attempted to type')
    }.must_raise RuntimeError
    
    exception.message.must_match /text we attempted to type/ 
    exception.message.must_match /reason for failure/ 
    exception.message.must_match /details about failure/ 
  end

end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
frank-cucumber-0.9.5.pre4 test/keyboard_helper_test.rb
frank-cucumber-0.9.5.pre3 test/keyboard_helper_test.rb
frank-cucumber-0.9.5.pre2 test/keyboard_helper_test.rb
frank-cucumber-0.9.5.pre1 test/keyboard_helper_test.rb
frank-cucumber-0.9.4 test/keyboard_helper_test.rb
frank-cucumber-0.9.3 test/keyboard_helper_test.rb
frank-cucumber-0.9.1 test/keyboard_helper_test.rb
frank-cucumber-0.9.0 test/keyboard_helper_test.rb
frank-cucumber-0.8.17 test/keyboard_helper_test.rb
frank-cucumber-0.8.16 test/keyboard_helper_test.rb
frank-cucumber-0.8.15 test/keyboard_helper_test.rb
frank-cucumber-0.8.14 test/keyboard_helper_test.rb