Class: RestService

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/rack-rest-rspec/lib/rest_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ RestService

Returns a new instance of RestService.



12
13
14
15
16
17
18
19
20
21
# File 'lib/rack-rest-rspec/lib/rest_service.rb', line 12

def initialize(params = {})
  defaults = {
    :service => Sinatra::Base,
    :path => '/'
  }
  defaults.merge! params
  @service = defaults[:service]
  @path = defaults[:path]
  @browser = Rack::Test::Session.new(Rack::MockSession.new(@service))
end

Instance Attribute Details

#browserObject (readonly)

Returns the value of attribute browser.



10
11
12
# File 'lib/rack-rest-rspec/lib/rest_service.rb', line 10

def browser
  @browser
end

#pathObject (readonly)

Returns the value of attribute path.



8
9
10
# File 'lib/rack-rest-rspec/lib/rest_service.rb', line 8

def path
  @path
end

#serviceObject (readonly)

Returns the value of attribute service.



9
10
11
# File 'lib/rack-rest-rspec/lib/rest_service.rb', line 9

def service
  @service
end

Instance Method Details

#returned_dataObject



25
26
27
# File 'lib/rack-rest-rspec/lib/rest_service.rb', line 25

def returned_data
  return JSON::parse(@browser.last_response.body, symbolize_names: true)
end