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.



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

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.



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

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.



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

def service
  @service
end

Instance Method Details

#returned_dataObject



23
24
25
# File 'lib/rack-rest-rspec/lib/rest_service.rb', line 23

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