require 'active_support/core_ext/string/inflections' Given 'I am performing a {word} on the {string} API' do |operation, api_name| @exchange = api_name.camelize.constantize.send operation end Given 'I set the {word} to {string}' do |key, value| @exchange[key] = value end Given 'I use the path {word}' do |suburl| @exchange.suburl = suburl end Given 'I filter {string} by {string}' do |filter_key, filter_value| transformed_key = filter_key.to_sym if @exchange.override_parameters[:q] @exchange.override_parameters[:q][transformed_key] = filter_value else @exchange.override_parameters[:q] = { transformed_key => filter_value } end end # This is getting quite technical Given 'I set header {string} to {string}' do |header_name, header_value| if @exchange.override_parameters[:params] @exchange.override_parameters[:params][header_name] = header_value else @exchange.override_parameters[:params] = { header_name => header_value } end end When 'I make the request' do @exchange.call end Then 'it should have the {word} {string}' do |key, expected_value| expect(@exchange[key]).to eq expected_value end Then 'it should have the {string} {string}' do |key_string, expected_value| key = key_string.tr(' ', '_') actual_value = @exchange.respond_to?(key) ? @exchange.send(key) : @exchange[key] expect(actual_value.to_s).to eq expected_value end Then 'it should be successful' do expect(200..299).to cover @exchange.status_code end