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