ruby-resty 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/README.md +26 -8
  2. data/Rakefile +7 -0
  3. data/lib/resty/cli.rb +21 -13
  4. data/lib/resty/commands/method_command.rb +27 -12
  5. data/lib/resty/{cli_options.rb → options.rb} +20 -12
  6. data/lib/resty/override_pry_help.rb +17 -0
  7. data/lib/resty/pretty_printer.rb +59 -0
  8. data/lib/resty/repl.rb +6 -4
  9. data/lib/resty/request.rb +18 -10
  10. data/lib/resty.rb +6 -3
  11. data/lib/version.rb +1 -1
  12. data/ruby-resty.gemspec +5 -1
  13. data/spec/lib/resty/commands/method_command_spec.rb +22 -14
  14. data/spec/lib/resty/options_spec.rb +111 -0
  15. data/spec/lib/resty/pretty_printer_spec.rb +110 -0
  16. data/spec/lib/resty/request_spec.rb +69 -45
  17. data/spec/requests/commands/method_command_request_spec.rb +150 -0
  18. data/spec/server.rb +34 -0
  19. data/spec/spec_helper.rb +48 -0
  20. data/spec/vcr/method_command/delete_returns_200.yml +79 -0
  21. data/spec/vcr/method_command/delete_sends_headers.yml +46 -0
  22. data/spec/vcr/method_command/get_non_json_response_returns_200.yml +89 -0
  23. data/spec/vcr/method_command/get_non_json_response_returns_response.yml +89 -0
  24. data/spec/vcr/method_command/get_non_json_response_sends_headers.yml +89 -0
  25. data/spec/vcr/method_command/get_returns_200.yml +79 -0
  26. data/spec/vcr/method_command/get_returns_response.yml +79 -0
  27. data/spec/vcr/method_command/get_sends_headers.yml +44 -0
  28. data/spec/vcr/method_command/get_with_per_request_headers_returns_200.yml +46 -0
  29. data/spec/vcr/method_command/get_with_per_request_headers_returns_response.yml +46 -0
  30. data/spec/vcr/method_command/get_with_per_request_headers_sends_headers.yml +46 -0
  31. data/spec/vcr/method_command/get_without_per_request_headers_returns_200.yml +46 -0
  32. data/spec/vcr/method_command/get_without_per_request_headers_returns_response.yml +46 -0
  33. data/spec/vcr/method_command/get_without_per_request_headers_sends_headers.yml +46 -0
  34. data/spec/vcr/method_command/head_returns_200.yml +79 -0
  35. data/spec/vcr/method_command/head_sends_headers.yml +46 -0
  36. data/spec/vcr/method_command/options_returns_200.yml +79 -0
  37. data/spec/vcr/method_command/options_sends_headers.yml +46 -0
  38. data/spec/vcr/method_command/patch_returns_204.yml +87 -0
  39. data/spec/vcr/method_command/patch_sends_headers.yml +50 -0
  40. data/spec/vcr/method_command/post_returns_200.yml +87 -0
  41. data/spec/vcr/method_command/post_returns_created_object.yml +87 -0
  42. data/spec/vcr/method_command/post_sends_headers.yml +50 -0
  43. data/spec/vcr/method_command/put_returns_204.yml +79 -0
  44. data/spec/vcr/method_command/put_sends_headers.yml +42 -0
  45. metadata +135 -16
  46. data/lib/resty/commands/method_output.rb +0 -43
  47. data/spec/lib/resty/cli_options_spec.rb +0 -103
  48. data/spec/lib/resty/commands/method_output_spec.rb +0 -58
data/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  Ruby-Resty is a ruby port of [Resty][1], which provides a simple way to interact with RESTful services. Ruby-Resty was
6
6
  ported to be shell agnostic and for easier community development.
7
7
 
8
- The resty REPL is built on top of [Pry][2] for niceties like [Custom Commands][3], history management, interactive
8
+ The resty REPL is built on top of [Pry][2] to leverage [Custom Commands][3], history management, an interactive
9
9
  help system, and most importantly, using plain old Ruby.
10
10
 
11
11
  # Installation
@@ -27,13 +27,18 @@ To get started, you can enter the REPL by providing the `host` option.
27
27
 
28
28
  ```
29
29
  ruby-resty --host http://nyan.cat
30
- resty>
31
30
  ```
32
31
 
33
32
  If you would like headers to be attached with every request, you can do so:
34
33
 
35
34
  ```
36
- ruby-resty --host http://nyan.cat --headers X-NYAN-CAT-SECRET-KEY=nyan_nyan X-NYAN-TYPE=octo
35
+ ruby-resty --host http://nyan.cat --headers X-NYAN-CAT-SECRET-KEY:nyan_nyan X-NYAN-TYPE:octo
36
+ ```
37
+
38
+ HTTP Basic Authentication can be attached to the hostname
39
+
40
+ ```
41
+ ruby-resty --host http://nyan.cat --username Leeroy --password Jenkins
37
42
  ```
38
43
 
39
44
  ### Options
@@ -42,11 +47,14 @@ The REPL accepts the following options that are attached to each request. This p
42
47
  requests without having to specify headers everytime.
43
48
 
44
49
  ```
45
- --alias, -a : The per-host entry to use in ~/.ruby_resty.yml
46
- --host, -h : The hostname of the REST service. Ex: http://nyan.cat
47
- --headers, -H : The headers attached to each request. Ex: X-NYAN-CAT-SECRET-KEY=nyan_nyan
48
- --verbose, -v : Verbose mode
49
- --config, -c : Use host information from ~/.ruby_resty.yml
50
+ --alias, -a : The per-host entry to use in ~/.ruby_resty.yml
51
+ --headers, -H : The headers attached to each request. Ex: X-NYAN-CAT-SECRET-KEY:nyan_nyan
52
+ --host, -h : The hostname of the REST service. Ex: http://nyan.cat
53
+ --username, -u : HTTP basic authentication username
54
+ --password, -p : HTTP basic authentication password
55
+ --verbose, -v : Verbose mode
56
+ --version, -e : Print verison and exit
57
+ --config, -c : Use host information from ~/.ruby_resty.yml
50
58
  ```
51
59
 
52
60
  ### Requests
@@ -100,6 +108,14 @@ resty> data = {nyan_cat: {name: "oliver", color: "blue"} }
100
108
  resty> POST /api/cats data
101
109
  ```
102
110
 
111
+ #### Per-request headers
112
+
113
+ Headers sent with individual requests are supported:
114
+
115
+ ```
116
+ resty> GET /api/cats/1 -H filter:tail-length -H filter:name
117
+ ```
118
+
103
119
  ### Responses
104
120
 
105
121
  After a request is returned, the resulting JSON response is parsed into a ruby hash and stored in `response`:
@@ -148,6 +164,8 @@ nyan:
148
164
  headers:
149
165
  header_name: header_value
150
166
  header_name2: header_value2
167
+ username: (optional)
168
+ password: (optional)
151
169
  ```
152
170
 
153
171
  Now instead of starting the REPL like:
data/Rakefile CHANGED
@@ -22,3 +22,10 @@ task :copy_config do
22
22
  puts "Copied config file to #{config_file}"
23
23
  end
24
24
  end
25
+
26
+ namespace :test do
27
+ desc "Starts the test server used for integration testing"
28
+ task :server do
29
+ `ruby ./spec/server.rb`
30
+ end
31
+ end
data/lib/resty/cli.rb CHANGED
@@ -4,29 +4,37 @@ module Resty
4
4
  class Cli
5
5
 
6
6
  def run
7
- p = Trollop::Parser.new do
7
+ options = Trollop::options do
8
+ version "Version: #{Resty::VERSION}\n"
8
9
  opt :alias, "The per-host entry to use in ~/.ruby_resty.yml", type: :string, short: "-a"
10
+ opt :headers, "The headers sent with each request. Ex: X-NYAN-CAT-SECRET-KEY:nyan_nyan",
11
+ type: :strings, short: "-H"
9
12
  opt :host, "The hostname of the REST service. Ex: http://nyan.cat", type: :string, short: "-h"
10
- opt :headers, "The headers sent with each request. Ex: X-NYAN-CAT-SECRET-KEY=nyan_nyan",
11
- type: :strings, short: "-H"
13
+ opt :username, "HTTP basic authentication username", type: :string, short: "-u"
14
+ opt :password, "HTTP basic authentication password", type: :string, short: "-p"
12
15
  opt :verbose, "Verbose mode", short: "-v"
13
16
  end
14
17
 
15
- Trollop::with_standard_exception_handling p do
16
- options = p.parse(ARGV)
17
-
18
- if (options[:alias] && options[:host]) || (options[:alias].nil? && options[:host].nil?)
19
- puts "Please specify an alias OR a host."
20
- raise Trollop::HelpNeeded
21
- elsif options.empty?
22
- raise Trollop::HelpNeeded
23
- end
24
-
18
+ if missing_host_or_alias?(options)
19
+ puts "Please specify an alias OR a host. Use --help for more info."
20
+ elsif basic_auth_invalid?(options)
21
+ puts "Please specify a username and password. Use --help for more info."
22
+ else
25
23
  Resty::Repl.start(options)
26
24
  end
27
25
 
28
26
  rescue ConfigFileError => e
29
27
  puts e.message
30
28
  end
29
+
30
+ def missing_host_or_alias?(options)
31
+ (options[:alias] && options[:host]) || (options[:alias].nil? && options[:host].nil?)
32
+ end
33
+
34
+ def basic_auth_invalid?(options)
35
+ username = options[:username]
36
+ password = options[:password]
37
+ (username && password.nil?) || (username.nil? && password)
38
+ end
31
39
  end
32
40
  end
@@ -1,4 +1,8 @@
1
- Pry::Commands.create_command /(get|put|post|delete|head|option|patch|trace)/i, listing: "method-command" do
1
+ require 'hashie'
2
+
3
+ Pry::Commands.create_command /(get|put|post|delete|head|options|patch)/i,
4
+ listing: "method-command", :keep_retval => true do
5
+
2
6
  description "Performs an HTTP request to the specified path: METHOD PATH [DATA]"
3
7
 
4
8
  banner <<-BANNER
@@ -7,6 +11,7 @@ Pry::Commands.create_command /(get|put|post|delete|head|option|patch|trace)/i, l
7
11
  Examples:
8
12
  ---------
9
13
  GET /api/nyan
14
+ GET /api/nyan -H filter:color -H type:space
10
15
  DELETE /api/nyan
11
16
  PUT /api/nyan {"name": "Jan"}
12
17
  POST /api/nyan {"name": "Jeff"}
@@ -26,24 +31,30 @@ Pry::Commands.create_command /(get|put|post|delete|head|option|patch|trace)/i, l
26
31
  shellwords: false
27
32
  )
28
33
 
34
+ def setup
35
+ @user_auth = nil
36
+ end
37
+
29
38
  def process
30
39
  if path_missing?
31
- output.puts("Missing path\n\n")
32
- run("help method-command")
40
+ "Missing path. Type 'method-command -h' for more info."
33
41
  elsif data_invalid?
34
- output.puts("Invalid data\n\n")
35
- run("help method-command")
42
+ "Invalid data. Type 'method-command -h' for more info."
36
43
  else
37
44
  params = { method: http_method, path: path, data: data }
38
- request = Resty::Request.new(cli_options, params)
39
- request.send_request do |response, request|
40
- method_output = Resty::Commands::MethodOutput.new(cli_options.verbose?, response, request)
41
- output.puts(method_output.generate)
45
+ request = Resty::Request.new(global_options, params)
46
+ request.send_request({headers: request_headers}) do |response, request|
42
47
  eval_response(response)
48
+ return Hashie::Mash.new(response: response, request: request)
43
49
  end
44
50
  end
45
51
  end
46
52
 
53
+ def options(opt)
54
+ opt.on "H=", :headers, "Headers sent per-request. Ex: -H header:value -H header:value",
55
+ as: Array
56
+ end
57
+
47
58
  private
48
59
 
49
60
  def path_missing?
@@ -57,7 +68,7 @@ Pry::Commands.create_command /(get|put|post|delete|head|option|patch|trace)/i, l
57
68
  def eval_response(response)
58
69
  target.eval("response = #{JSON.parse(response)}")
59
70
  rescue
60
- target.eval("response = nil")
71
+ target.eval("response = '#{response}'")
61
72
  end
62
73
 
63
74
  def build_data
@@ -81,8 +92,8 @@ Pry::Commands.create_command /(get|put|post|delete|head|option|patch|trace)/i, l
81
92
  JSON.parse(input) rescue nil
82
93
  end
83
94
 
84
- def cli_options
85
- @cli_options ||= eval "self", target
95
+ def global_options
96
+ @global_options ||= eval "self", target
86
97
  end
87
98
 
88
99
  def http_method
@@ -96,4 +107,8 @@ Pry::Commands.create_command /(get|put|post|delete|head|option|patch|trace)/i, l
96
107
  def data
97
108
  @data ||= build_data
98
109
  end
110
+
111
+ def request_headers
112
+ opts[:headers] ? Resty::Options.parse_headers(opts[:headers]) : {}
113
+ end
99
114
  end
@@ -1,7 +1,7 @@
1
1
  require 'yaml'
2
2
 
3
3
  module Resty
4
- class CliOptions
4
+ class Options
5
5
  attr_reader :options
6
6
 
7
7
  CONFIG_FILE = "#{Dir.home}/.ruby_resty.yml"
@@ -10,7 +10,7 @@ module Resty
10
10
  @options = options
11
11
 
12
12
  if options[:headers]
13
- parse_command_line_headers
13
+ options[:headers] = Options.parse_headers(options[:headers])
14
14
  elsif host_alias
15
15
  load_config_file
16
16
  end
@@ -32,18 +32,31 @@ module Resty
32
32
  options[:headers] || {}
33
33
  end
34
34
 
35
- private
35
+ def username
36
+ options[:username]
37
+ end
36
38
 
37
- def parse_command_line_headers
38
- options[:headers] = options[:headers].inject({}) do |hash, header|
39
- hash.merge(build_pair(header))
40
- end
39
+ def password
40
+ options[:password]
41
41
  end
42
42
 
43
+ def self.parse_headers(headers)
44
+ headers.inject({}) { |hash, header| hash.merge(build_pair(header)) }
45
+ end
46
+
47
+ def self.build_pair(header)
48
+ pair = header.split(":")
49
+ { pair.first.to_sym => pair.last }
50
+ end
51
+
52
+ private
53
+
43
54
  def load_config_file
44
55
  read_config_file.tap do |config|
45
56
  options[:host] = config[host_alias]["host"]
46
57
  options[:headers] = config[host_alias]["headers"]
58
+ options[:username] = config[host_alias]["username"]
59
+ options[:password] = config[host_alias]["password"]
47
60
  end
48
61
  end
49
62
 
@@ -64,11 +77,6 @@ module Resty
64
77
  raise ConfigFileError, "Alias missing from #{CONFIG_FILE}: #{host_alias}"
65
78
  end
66
79
  end
67
-
68
- def build_pair(header)
69
- pair = header.split("=")
70
- { pair.first.to_sym => pair.last }
71
- end
72
80
  end
73
81
 
74
82
  class ConfigFileError < StandardError; end
@@ -0,0 +1,17 @@
1
+ class Pry
2
+ class Command::Help < Pry::ClassCommand
3
+ COMMANDS = %w{method-command}
4
+
5
+ def visible_commands
6
+ visible = {}
7
+ commands.each do |key, command|
8
+ visible[key] = command if COMMANDS.include?(command.options[:listing])
9
+ end
10
+ visible
11
+ end
12
+
13
+ def help_text_for_commands(name, commands)
14
+ commands.first.banner
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,59 @@
1
+
2
+ module Resty
3
+ class PrettyPrinter
4
+ attr_accessor :options, :params
5
+
6
+ def initialize(options, params)
7
+ @options = options
8
+ @params = params
9
+ end
10
+
11
+ def generate
12
+ if params.is_a? Hashie::Mash
13
+ output = ""
14
+ if verbose?
15
+ output += build_line("#{request.method.upcase} #{request.url}")
16
+ request.processed_headers.each { |key, value| output += build_line("#{key}: #{value}") }
17
+ output += "\n"
18
+
19
+ output += build_line("Response Code: #{response.code}")
20
+ response.headers.each { |key, value| output += build_line("#{key}: #{value}") }
21
+ else
22
+ output += build_line("Response Code: #{response.code}")
23
+ end
24
+
25
+ output += pretty_print_response(response)
26
+ else
27
+ params
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def build_line(line)
34
+ "> #{line}\n"
35
+ end
36
+
37
+ def pretty_print_response(response)
38
+ return response if response == ""
39
+ parsed_response = JSON.parse(response)
40
+ MultiJson.dump(parsed_response, { pretty: true }) || ""
41
+ rescue => e
42
+ response
43
+ end
44
+
45
+ private
46
+
47
+ def verbose?
48
+ options.verbose?
49
+ end
50
+
51
+ def request
52
+ params[:request]
53
+ end
54
+
55
+ def response
56
+ params[:response]
57
+ end
58
+ end
59
+ end
data/lib/resty/repl.rb CHANGED
@@ -1,23 +1,25 @@
1
1
  require 'readline'
2
- require 'pry'
3
2
 
4
3
  module Resty
5
4
  class Repl
6
5
  include Readline
7
6
 
8
- attr_accessor :cli_options, :interrupted
7
+ attr_accessor :options, :interrupted
9
8
 
10
9
  def initialize(resty_options)
11
- @cli_options = Resty::CliOptions.new(resty_options)
10
+ @options = Resty::Options.new(resty_options)
12
11
 
13
12
  Pry.config.prompt = [ proc { "resty> " }, proc { "*>" }]
14
13
  Pry.config.history.file = "~/.ruby_resty_history"
14
+ Pry.config.print = proc do |output, value|
15
+ output.puts(Resty::PrettyPrinter.new(options, value).generate)
16
+ end
15
17
  end
16
18
 
17
19
  def self.start(resty_options)
18
20
  new(resty_options).tap do |repl|
19
21
  Pry.config.input = repl
20
- repl.cli_options.pry
22
+ repl.options.pry
21
23
  end
22
24
  end
23
25
 
data/lib/resty/request.rb CHANGED
@@ -3,19 +3,16 @@ require 'json'
3
3
  module Resty
4
4
  class Request
5
5
 
6
- attr_reader :params, :cli_options
6
+ attr_reader :params, :global_options
7
7
 
8
- def initialize(cli_options, params)
9
- @cli_options = cli_options
8
+ def initialize(global_options, params)
9
+ @global_options = global_options
10
10
  @params = params
11
11
  end
12
12
 
13
- def send_request
14
- if Resty::Request.data_required?(method)
15
- RestClient.send(method, url, data, cli_options.headers) { |*params| yield params }
16
- else
17
- RestClient.send(method, url, cli_options.headers) { |*params| yield params }
18
- end
13
+ def send_request(options = {})
14
+ request_options[:headers].merge!(options[:headers]) if options[:headers]
15
+ RestClient::Request.new(request_options).execute { |*params| yield params }
19
16
  end
20
17
 
21
18
  def self.data_required?(method)
@@ -24,8 +21,19 @@ module Resty
24
21
 
25
22
  private
26
23
 
24
+ def request_options
25
+ @request_options ||= {}.tap do |options|
26
+ options[:method] = method
27
+ options[:headers] = global_options.headers
28
+ options[:url] = url
29
+ options[:user] = global_options.username if global_options.username
30
+ options[:password] = global_options.password if global_options.password
31
+ options[:payload] = data if Resty::Request.data_required?(method)
32
+ end
33
+ end
34
+
27
35
  def url
28
- "#{cli_options.host}#{path}"
36
+ "#{global_options.host}#{path}"
29
37
  end
30
38
 
31
39
  def method
data/lib/resty.rb CHANGED
@@ -1,13 +1,16 @@
1
- require 'rest_client'
2
1
  require 'active_support'
3
2
  require 'multi_json'
3
+ require 'pry'
4
+ require 'rest_client'
4
5
 
5
6
  module Resty
6
7
  end
7
8
 
9
+ require_relative "version"
8
10
  require_relative "resty/cli"
9
- require_relative "resty/cli_options"
11
+ require_relative "resty/options"
12
+ require_relative "resty/override_pry_help"
13
+ require_relative "resty/pretty_printer"
10
14
  require_relative "resty/repl"
11
15
  require_relative "resty/request"
12
16
  require_relative "resty/commands/method_command"
13
- require_relative "resty/commands/method_output"
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Resty
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/ruby-resty.gemspec CHANGED
@@ -16,10 +16,11 @@ Gem::Specification.new do |gem|
16
16
  gem.executables << 'ruby-resty'
17
17
 
18
18
  gem.add_dependency 'active_support'
19
+ gem.add_dependency 'hashie'
20
+ gem.add_dependency 'multi_json'
19
21
  gem.add_dependency 'pry'
20
22
  gem.add_dependency 'rest-client', '1.6.7'
21
23
  gem.add_dependency 'trollop'
22
- gem.add_dependency 'multi_json'
23
24
 
24
25
  gem.add_development_dependency 'bourne', "1.4.0"
25
26
  gem.add_development_dependency 'guard'
@@ -28,4 +29,7 @@ Gem::Specification.new do |gem|
28
29
  gem.add_development_dependency 'pry'
29
30
  gem.add_development_dependency 'rspec'
30
31
  gem.add_development_dependency 'rake'
32
+ gem.add_development_dependency 'sinatra'
33
+ gem.add_development_dependency 'vcr'
34
+ gem.add_development_dependency 'webmock'
31
35
  end
@@ -17,13 +17,13 @@ describe "MethodCommand" do
17
17
  end
18
18
 
19
19
  it "responds lower case method" do
20
- %w{get put post delete head option patch trace}.each do |method|
20
+ %w{get put post delete head options patch}.each do |method|
21
21
  pry_eval("#{method}").start_with?("Missing").should be_true
22
22
  end
23
23
  end
24
24
 
25
25
  it "responds to case-insentivity" do
26
- %w{GET Put PoSt delete head option patch trace}.each do |method|
26
+ %w{GET Put PoSt delete head options patch}.each do |method|
27
27
  pry_eval("#{method}").start_with?("Missing").should be_true
28
28
  end
29
29
  end
@@ -49,7 +49,6 @@ describe "MethodCommand" do
49
49
 
50
50
  context "request doesn't require data" do
51
51
  before(:each) do
52
- Resty::Commands::MethodOutput.stubs(:new).returns(stub(:generate))
53
52
  Resty::Request.stubs(:new).returns(request)
54
53
  request.stubs(:send_request).yields(response, request)
55
54
  pry_eval("get /api/nyan")
@@ -66,7 +65,6 @@ describe "MethodCommand" do
66
65
  let(:method_output) { stub(generate: "")}
67
66
 
68
67
  before(:each) do
69
- Resty::Commands::MethodOutput.stubs(:new).returns(method_output)
70
68
  request.stubs(:send_request).yields(response, request)
71
69
  end
72
70
 
@@ -82,8 +80,7 @@ describe "MethodCommand" do
82
80
  end
83
81
 
84
82
  it "sends request" do
85
- Resty::Commands::MethodOutput.should have_received(:new).with(false, response,request)
86
- method_output.should have_received(:generate)
83
+ request.should have_received(:send_request)
87
84
  end
88
85
  end
89
86
  end
@@ -99,8 +96,7 @@ describe "MethodCommand" do
99
96
  end
100
97
 
101
98
  it "sends request" do
102
- Resty::Commands::MethodOutput.should have_received(:new).with(false, response,request)
103
- method_output.should have_received(:generate)
99
+ request.should have_received(:send_request)
104
100
  end
105
101
  end
106
102
 
@@ -117,8 +113,7 @@ describe "MethodCommand" do
117
113
  end
118
114
 
119
115
  it "sends request" do
120
- Resty::Commands::MethodOutput.should have_received(:new).with(false, response,request)
121
- method_output.should have_received(:generate)
116
+ request.should have_received(:send_request)
122
117
  end
123
118
  end
124
119
 
@@ -134,8 +129,7 @@ describe "MethodCommand" do
134
129
  end
135
130
 
136
131
  it "sends request" do
137
- Resty::Commands::MethodOutput.should have_received(:new).with(false, response,request)
138
- method_output.should have_received(:generate)
132
+ request.should have_received(:send_request)
139
133
  end
140
134
  end
141
135
  end
@@ -151,8 +145,22 @@ describe "MethodCommand" do
151
145
  end
152
146
 
153
147
  it "sends request" do
154
- Resty::Commands::MethodOutput.should have_received(:new).with(false, response,request)
155
- method_output.should have_received(:generate)
148
+ request.should have_received(:send_request)
149
+ end
150
+ end
151
+
152
+ context "with request options" do
153
+ before(:each) do
154
+ pry_eval("get /api/nyan -H name:nyaa -H address:space")
155
+ end
156
+
157
+ it "creates request" do
158
+ params = { method: "get", path: "/api/nyan", data: nil }
159
+ Resty::Request.should have_received(:new).with(anything, params)
160
+ end
161
+
162
+ it "sends request" do
163
+ request.should have_received(:send_request).with(headers: { name: "nyaa", address: "space" })
156
164
  end
157
165
  end
158
166
  end