dvr 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +34 -0
- data/Rakefile +6 -0
- data/bin/dvr +8 -0
- data/dvr.gemspec +29 -0
- data/lib/dvr.rb +42 -0
- data/lib/dvr/cli.rb +2 -0
- data/lib/dvr/cli/app.rb +34 -0
- data/lib/dvr/configuration.rb +30 -0
- data/lib/dvr/episode.rb +48 -0
- data/lib/dvr/recorder.rb +26 -0
- data/lib/dvr/season.rb +41 -0
- data/lib/dvr/version.rb +3 -0
- data/spec/dvr/configuration_spec.rb +27 -0
- data/spec/dvr/episode_spec.rb +75 -0
- data/spec/dvr/recorder_spec.rb +23 -0
- data/spec/dvr/season_spec.rb +24 -0
- data/spec/dvr_spec.rb +27 -0
- data/spec/fixtures/requests/rspec_api_documentation.json +50 -0
- data/spec/spec_helper.rb +13 -0
- data/spec/support/server.rb +48 -0
- metadata +195 -0
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Kyle Conarro
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# DVR [](https://travis-ci.org/kconarro14/dvr)
|
2
|
+
|
3
|
+
DVR makes it easy to mimic your Rails API backend by generating a fake server using recorded HTTP responses.
|
4
|
+
|
5
|
+
The goals of DVR are as follows:
|
6
|
+
|
7
|
+
* Ease API client testing for Rails API backends
|
8
|
+
* Simplify keeping client testing synchronized with changes to the backend
|
9
|
+
|
10
|
+
A nice side effect of using DVR is that it relies on recorded API responses (for now, in the form of [rspec-api-documentation](https://github.com/zipmark/rspec_api_documentation) docs).
|
11
|
+
|
12
|
+
## Installation & Usage
|
13
|
+
``` bash
|
14
|
+
$ gem install dvr
|
15
|
+
$ dvr record --episode-location '/absolute/path/to/rspec-api-documentation'
|
16
|
+
```
|
17
|
+
*Note that this is a command-line tool that doesn't need to be in your Gemfile.
|
18
|
+
|
19
|
+
### Options
|
20
|
+
``` bash
|
21
|
+
-l, [--episode-location=EPISODE_LOCATION] # The location of the recorded HTTP responses
|
22
|
+
-n, [--filename=FILENAME] # The name for the recorded server file
|
23
|
+
-f, [--episode-format=EPISODE_FORMAT] # The format of the provided files
|
24
|
+
-s, [--episode-source=EPISODE_SOURCE] # The source of the JSON files
|
25
|
+
-l, --episode-location=EPISODE_LOCATION # The location of the JSON files to record
|
26
|
+
-d, [--destination=DESTINATION] # The destination for the recorded server file
|
27
|
+
```
|
28
|
+
## Contributing
|
29
|
+
|
30
|
+
1. Fork it
|
31
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
32
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
33
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
34
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/bin/dvr
ADDED
data/dvr.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'dvr/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "dvr"
|
8
|
+
spec.version = Dvr::VERSION
|
9
|
+
spec.authors = ["Kyle Conarro"]
|
10
|
+
spec.email = ["kyle.conarro@rigor.com"]
|
11
|
+
spec.description = "Mimic your Rails API backend by generating a fake server using recorded HTTP responses"
|
12
|
+
spec.summary = "DVR makes it easy to mimic your Rails API backend by generating a fake server using recorded HTTP responses"
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
spec.add_development_dependency "pry"
|
25
|
+
|
26
|
+
spec.add_dependency 'thor'
|
27
|
+
spec.add_dependency 'json'
|
28
|
+
spec.add_dependency 'sinatra'
|
29
|
+
end
|
data/lib/dvr.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'json'
|
2
|
+
require "dvr/version"
|
3
|
+
require "dvr/configuration"
|
4
|
+
require "dvr/episode"
|
5
|
+
require "dvr/recorder"
|
6
|
+
require "dvr/season"
|
7
|
+
|
8
|
+
module DVR
|
9
|
+
extend self
|
10
|
+
|
11
|
+
def play
|
12
|
+
`bundle exec ruby #{DVR.configuration.recording_location}`
|
13
|
+
end
|
14
|
+
|
15
|
+
def record
|
16
|
+
raise DVR::InvalidConfiguration unless configuration.episode_location
|
17
|
+
recorder.get_season
|
18
|
+
end
|
19
|
+
|
20
|
+
def record_and_download
|
21
|
+
record.download
|
22
|
+
puts "Downloaded to #{download_location}"
|
23
|
+
end
|
24
|
+
|
25
|
+
def recorder
|
26
|
+
@recorder ||= Recorder.new
|
27
|
+
end
|
28
|
+
|
29
|
+
def download_location
|
30
|
+
@download_location ||= File.join(DVR.configuration.destination, DVR.configuration.filename)
|
31
|
+
end
|
32
|
+
|
33
|
+
def prep_destination
|
34
|
+
unless File.directory?(DVR.configuration.destination)
|
35
|
+
puts "Created destination directory at #{DVR.configuration.destination}"
|
36
|
+
Dir.mkdir(DVR.configuration.destination)
|
37
|
+
else
|
38
|
+
puts "Used existing destination directory at #{DVR.configuration.destination}"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
data/lib/dvr/cli.rb
ADDED
data/lib/dvr/cli/app.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
module DVR
|
2
|
+
module CLI
|
3
|
+
class App < Thor
|
4
|
+
namespace :dvr
|
5
|
+
|
6
|
+
desc "record", "Record episodes from API docs and playback as a Sinatra server file"
|
7
|
+
method_option :episode_location, :aliases => "-l", :desc => "The location of the JSON files to record", :required => true
|
8
|
+
method_option :episode_format, :aliases => "-f", :desc => "The format of the provided files", :required => false
|
9
|
+
method_option :episode_source, :aliases => "-s", :desc => "The source of the JSON files", :required => false
|
10
|
+
method_option :destination, :aliases => "-d", :desc => "The destination for the recorded server file", :required => false
|
11
|
+
method_option :filename, :aliases => "-n", :desc => "The name for the recorded server file", :required => false
|
12
|
+
def record
|
13
|
+
configure_options!
|
14
|
+
DVR.record_and_download
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "play", "Play back recorded episodes by starting a Sinatra server"
|
18
|
+
method_option :recording_location, :aliases => "-r", :desc => "The location of the recorded Sinatra file", :required => true
|
19
|
+
def play
|
20
|
+
configure_options!
|
21
|
+
DVR.play
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def configure_options!
|
27
|
+
DVR.configure do |config|
|
28
|
+
options.each {|option, value| config.send("#{option}=", value)}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module DVR
|
2
|
+
|
3
|
+
class Configuration
|
4
|
+
attr_accessor :episode_format, :episode_location, :episode_source, :filename, :destination, :recording_location
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@episode_format = :rspec_api_documentation
|
8
|
+
@episode_location = nil
|
9
|
+
@episode_source = :filesystem
|
10
|
+
@filename = 'dvr_server.rb'
|
11
|
+
@destination = "#{Dir.pwd}/dvr"
|
12
|
+
@recording_location = File.join(@destination, @filename)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
class InvalidConfiguration < Exception; end
|
18
|
+
|
19
|
+
extend self
|
20
|
+
attr_accessor :configuration
|
21
|
+
|
22
|
+
def configuration
|
23
|
+
@configuration ||= Configuration.new
|
24
|
+
end
|
25
|
+
|
26
|
+
def configure
|
27
|
+
yield(configuration)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
data/lib/dvr/episode.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
module DVR
|
2
|
+
class Episode
|
3
|
+
attr_reader :content
|
4
|
+
|
5
|
+
def self.batch_record contents
|
6
|
+
contents.map {|c| record(c)}
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.record content
|
10
|
+
new(content)
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize content
|
14
|
+
@content = content
|
15
|
+
end
|
16
|
+
|
17
|
+
def play
|
18
|
+
translate.map do |e|
|
19
|
+
"#{e[:method]} '#{e[:path]}' do\n '#{e[:response].body}'\nend\n\n"
|
20
|
+
end.join
|
21
|
+
end
|
22
|
+
|
23
|
+
def translate
|
24
|
+
data.map do |req|
|
25
|
+
{
|
26
|
+
:method => req['request_method'].downcase,
|
27
|
+
:path => req['request_path'].gsub('?', '/'),
|
28
|
+
:response => build_response(req)
|
29
|
+
}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def data
|
34
|
+
content.fetch('requests')
|
35
|
+
end
|
36
|
+
|
37
|
+
def build_response req
|
38
|
+
OpenStruct.new(
|
39
|
+
:status_code => req['response_status'],
|
40
|
+
:status_text => req['response_status_text'],
|
41
|
+
:body => req['response_body'],
|
42
|
+
:content_type => req['response_content_type'],
|
43
|
+
:headers => req['response_headers']
|
44
|
+
)
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
data/lib/dvr/recorder.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
module DVR
|
2
|
+
class Recorder
|
3
|
+
|
4
|
+
def get_episodes
|
5
|
+
puts "Recording episodes..."
|
6
|
+
Episode.batch_record(parsed_files)
|
7
|
+
end
|
8
|
+
|
9
|
+
def get_season
|
10
|
+
Season.new(get_episodes)
|
11
|
+
end
|
12
|
+
|
13
|
+
def files
|
14
|
+
Dir.glob("#{DVR.configuration.episode_location}/**/*.json").select {|f| !f.include?('index.json') }
|
15
|
+
end
|
16
|
+
|
17
|
+
def parsed_files
|
18
|
+
files.map {|f| parse_file(f)}
|
19
|
+
end
|
20
|
+
|
21
|
+
def parse_file file_loc
|
22
|
+
JSON.parse(File.open(file_loc).read)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
data/lib/dvr/season.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
module DVR
|
2
|
+
class Season
|
3
|
+
attr_reader :episodes
|
4
|
+
|
5
|
+
def initialize episodes
|
6
|
+
@episodes = episodes
|
7
|
+
end
|
8
|
+
|
9
|
+
def binge_watch
|
10
|
+
episodes.map(&:play).join
|
11
|
+
end
|
12
|
+
|
13
|
+
def download
|
14
|
+
puts 'Downloading season to destination...'
|
15
|
+
save
|
16
|
+
end
|
17
|
+
|
18
|
+
protected
|
19
|
+
|
20
|
+
def save
|
21
|
+
DVR.prep_destination
|
22
|
+
File.open(DVR.download_location, 'w') do |f|
|
23
|
+
f.write(sinatra_file_headers)
|
24
|
+
f.write(before_hooks)
|
25
|
+
f.write(binge_watch)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def before_hooks
|
30
|
+
%(\nbefore { request.path_info += '/'+ request.query_string if request.query_string && !request.query_string.empty? }\n\n)
|
31
|
+
end
|
32
|
+
|
33
|
+
def sinatra_requirements
|
34
|
+
['rubygems', 'sinatra']
|
35
|
+
end
|
36
|
+
|
37
|
+
def sinatra_file_headers
|
38
|
+
sinatra_requirements.map {|r| "require '#{r}'\n"}.join
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/dvr/version.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DVR::Configuration do
|
4
|
+
|
5
|
+
describe 'default options' do
|
6
|
+
it 'uses filesystem as the episode source' do
|
7
|
+
expect(subject.episode_source).to eq(:filesystem)
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'uses rspec api documentation as the episode format' do
|
11
|
+
expect(subject.episode_format).to eq(:rspec_api_documentation)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'has no default location from which to record episodes' do
|
15
|
+
expect(subject.episode_location).to be_nil
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'has a destination directory to record to' do
|
19
|
+
expect(subject.destination).to be_a(String)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'has a server name to use for the recorded file' do
|
23
|
+
expect(subject.filename).to be_a(String)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DVR::Episode do
|
4
|
+
let(:content) { JSON.parse(File.open(example_request_file).read) }
|
5
|
+
let(:batch_content) { [content] }
|
6
|
+
let(:episode) { DVR::Episode.new(content) }
|
7
|
+
|
8
|
+
describe 'defaults' do
|
9
|
+
it 'has content' do
|
10
|
+
expect(episode.content).to_not be_nil
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#translate' do
|
15
|
+
let(:translation) { episode.translate.first }
|
16
|
+
|
17
|
+
it 'translates the request method' do
|
18
|
+
expect(['get', 'post', 'put', 'patch', 'delete'].include?(translation.fetch(:method))).to be_true
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'translates request path' do
|
22
|
+
expect(translation.fetch(:path)).to be_a(String)
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'response' do
|
26
|
+
let(:response) { translation.fetch(:response) }
|
27
|
+
|
28
|
+
it 'builds a response object' do
|
29
|
+
expect(response).to be_an(OpenStruct)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'sets the status code' do
|
33
|
+
expect(response.status_code).to be_an(Integer)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'sets the status text' do
|
37
|
+
expect(response.status_text).to be_a(String)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'sets response body' do
|
41
|
+
expect(response.body).to be_a(String)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'sets the content type' do
|
45
|
+
expect(response.content_type).to be_a(String)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'sets the response headers' do
|
49
|
+
expect(response.headers).to be_a(Hash)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
describe '#record' do
|
56
|
+
it 'records a new episode' do
|
57
|
+
expect(DVR::Episode.record(content)).to be_a(DVR::Episode)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe '#batch_record' do
|
62
|
+
let(:result) { DVR::Episode.batch_record(batch_content) }
|
63
|
+
|
64
|
+
it 'records multiple episodes' do
|
65
|
+
expect(result).to be_an(Array)
|
66
|
+
expect(result.first).to be_an(DVR::Episode)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe '#play' do
|
71
|
+
it 'plays the episode back as a string' do
|
72
|
+
expect(episode.play).to be_a(String)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DVR::Recorder do
|
4
|
+
before do
|
5
|
+
DVR.configure {|c| c.episode_location = fixture_path}
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'finds files from the episode location' do
|
9
|
+
expect(File.file?(subject.files.first)).to be_true
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'parses files to json' do
|
13
|
+
expect(subject.parse_file(subject.files.first)).to be_a(Hash)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'records episodes' do
|
17
|
+
expect(subject.get_episodes.first).to be_a(DVR::Episode)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'records seasons' do
|
21
|
+
expect(subject.get_season).to be_a(DVR::Season)
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DVR::Season do
|
4
|
+
before { DVR.configure {|c| c.destination = '/my/destination' } }
|
5
|
+
|
6
|
+
let(:content) { JSON.parse(File.open(example_request_file).read) }
|
7
|
+
let(:episode) { DVR::Episode.new(content) }
|
8
|
+
let(:season) { DVR::Season.new([episode]) }
|
9
|
+
|
10
|
+
describe 'defaults' do
|
11
|
+
it 'has a collection of episodes' do
|
12
|
+
expect(season.episodes).to be_an(Array)
|
13
|
+
expect(season.episodes.first).to be_an(DVR::Episode)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#binge_watch' do
|
18
|
+
it 'plays all episodes in the season' do
|
19
|
+
expect(season.episodes.first).to receive(:play)
|
20
|
+
season.binge_watch
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
data/spec/dvr_spec.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Kernel
|
4
|
+
def `(cmd)
|
5
|
+
cmd
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
describe DVR do
|
10
|
+
describe '#play' do
|
11
|
+
it 'plays back a recorded server' do
|
12
|
+
expect(DVR.play).to eq("bundle exec ruby #{DVR.configuration.recording_location}")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#record' do
|
17
|
+
it 'records a season of episodes' do
|
18
|
+
expect(DVR.record).to be_a(DVR::Season)
|
19
|
+
expect(DVR.recorder).to receive(:get_season)
|
20
|
+
DVR.record
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'has a download location' do
|
25
|
+
expect(DVR.download_location).to be_a(String)
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
{
|
2
|
+
"resource": "Har Records",
|
3
|
+
"http_method": "POST",
|
4
|
+
"route": "api/v1/har_records",
|
5
|
+
"description": "Creating a single record",
|
6
|
+
"explanation": null,
|
7
|
+
"parameters": [
|
8
|
+
{
|
9
|
+
"name": "har_url",
|
10
|
+
"description": "The URL of the HAR file"
|
11
|
+
},
|
12
|
+
{
|
13
|
+
"name": "account_id",
|
14
|
+
"description": "The account id to associate with the record"
|
15
|
+
},
|
16
|
+
{
|
17
|
+
"name": "check_id",
|
18
|
+
"description": "The check id to associate with the record"
|
19
|
+
},
|
20
|
+
{
|
21
|
+
"name": "check_run_history_id",
|
22
|
+
"description": "The check run history id to associate with the record"
|
23
|
+
},
|
24
|
+
{
|
25
|
+
"name": "location_id",
|
26
|
+
"description": "The location id to associate with the record"
|
27
|
+
}
|
28
|
+
],
|
29
|
+
"requests": [
|
30
|
+
{
|
31
|
+
"request_method": "POST",
|
32
|
+
"request_path": "api/v1/har_records",
|
33
|
+
"request_body": "har_record[account_id]=1&har_record[check_id]=1&har_record[location_id]=1&har_record[check_run_history_id]=1&har_record[har_url]=https%3A%2F%2Fs3.amazonaws.com%2Fcheckdata.rigor.com%2F2.harp",
|
34
|
+
"request_headers": {
|
35
|
+
"Host": "example.org",
|
36
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
37
|
+
"Cookie": ""
|
38
|
+
},
|
39
|
+
"request_query_parameters": {
|
40
|
+
},
|
41
|
+
"request_content_type": "application/x-www-form-urlencoded",
|
42
|
+
"response_status": 202,
|
43
|
+
"response_status_text": "Accepted",
|
44
|
+
"response_body": "{\"job_id\":\"00c5ff51ca644e3f3de14dd5\"}",
|
45
|
+
"response_headers": {"X-Frame-Options":"SAMEORIGIN","X-XSS-Protection":"1; mode=block","X-Content-Type-Options":"nosniff","X-UA-Compatible":"chrome=1","Content-Type":"application/json; charset=utf-8","Cache-Control":"no-cache","X-Request-Id":"c972cd0e-608b-48a5-b1b9-cbcf7054ff42","X-Runtime":"0.028218","Content-Length":"37"},
|
46
|
+
"response_content_type": "application/json; charset=utf-8",
|
47
|
+
"curl": null
|
48
|
+
}
|
49
|
+
]
|
50
|
+
}
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'dvr'
|
2
|
+
|
3
|
+
def fixture_path
|
4
|
+
File.expand_path('../fixtures', __FILE__)
|
5
|
+
end
|
6
|
+
|
7
|
+
def example_request_file
|
8
|
+
"#{fixture_path}/requests/rspec_api_documentation.json"
|
9
|
+
end
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
config.color_enabled = true # Use color in STDOUT
|
13
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'sinatra'
|
3
|
+
|
4
|
+
before { request.path_info = request.path_info + '/' + request.query_string }
|
5
|
+
post 'api/v1/har_records' do
|
6
|
+
'{"job_id":"00c5ff51ca644e3f3de14dd5"}'
|
7
|
+
end
|
8
|
+
|
9
|
+
get '/api/v1/har_records/account_id=1' do
|
10
|
+
'{"count":1,"har_records":{"1940":{"id":"1940","source_url":null,"wait_time":null,"dns_time":null,"send_time":null,"connect_time":null,"blocked_time":null,"receive_time":null,"browser":null,"creator":null,"domain":null,"har_url":"https://s3.amazonaws.com/checkdata.rigor.com/49.harp","entry_count":null,"error_count":null,"dom_load_time":null,"page_load_time":null,"server_time":null,"page_size":null,"client_error_count":null,"server_error_count":null,"connection_error_count":null,"created_at":"2013-12-09T22:40:54Z","updated_at":"2013-12-09T22:40:54Z","started_date_time":null,"account_id":1,"check_id":1,"check_run_history_id":1,"location_id":1,"image_count":null,"javascript_count":null,"css_count":null,"html_count":null,"flash_count":null,"other_count":null,"run_record_id":null}},"results":[{"key":"har_records","id":"1940"}]}'
|
11
|
+
end
|
12
|
+
|
13
|
+
get '/api/v1/har_records/check_id=1' do
|
14
|
+
'{"count":1,"har_records":{"1941":{"id":"1941","source_url":null,"wait_time":null,"dns_time":null,"send_time":null,"connect_time":null,"blocked_time":null,"receive_time":null,"browser":null,"creator":null,"domain":null,"har_url":"https://s3.amazonaws.com/checkdata.rigor.com/50.harp","entry_count":null,"error_count":null,"dom_load_time":null,"page_load_time":null,"server_time":null,"page_size":null,"client_error_count":null,"server_error_count":null,"connection_error_count":null,"created_at":"2013-12-09T22:40:54Z","updated_at":"2013-12-09T22:40:54Z","started_date_time":null,"account_id":1,"check_id":1,"check_run_history_id":1,"location_id":1,"image_count":null,"javascript_count":null,"css_count":null,"html_count":null,"flash_count":null,"other_count":null,"run_record_id":null}},"results":[{"key":"har_records","id":"1941"}]}'
|
15
|
+
end
|
16
|
+
|
17
|
+
get '/api/v1/har_records/check_run_history_id=1' do
|
18
|
+
'{"count":1,"har_records":{"1937":{"id":"1937","source_url":null,"wait_time":null,"dns_time":null,"send_time":null,"connect_time":null,"blocked_time":null,"receive_time":null,"browser":null,"creator":null,"domain":null,"har_url":"https://s3.amazonaws.com/checkdata.rigor.com/46.harp","entry_count":null,"error_count":null,"dom_load_time":null,"page_load_time":null,"server_time":null,"page_size":null,"client_error_count":null,"server_error_count":null,"connection_error_count":null,"created_at":"2013-12-09T22:40:54Z","updated_at":"2013-12-09T22:40:54Z","started_date_time":null,"account_id":1,"check_id":1,"check_run_history_id":1,"location_id":1,"image_count":null,"javascript_count":null,"css_count":null,"html_count":null,"flash_count":null,"other_count":null,"run_record_id":null}},"results":[{"key":"har_records","id":"1937"}]}'
|
19
|
+
end
|
20
|
+
|
21
|
+
get '/api/v1/har_records/start=2013-11-11&end=2013-11-21' do
|
22
|
+
'{"count":1,"har_records":{"1936":{"id":"1936","source_url":null,"wait_time":null,"dns_time":null,"send_time":null,"connect_time":null,"blocked_time":null,"receive_time":null,"browser":null,"creator":null,"domain":null,"har_url":"https://s3.amazonaws.com/checkdata.rigor.com/45.harp","entry_count":null,"error_count":null,"dom_load_time":null,"page_load_time":null,"server_time":null,"page_size":null,"client_error_count":null,"server_error_count":null,"connection_error_count":null,"created_at":"2013-12-09T22:40:54Z","updated_at":"2013-12-09T22:40:54Z","started_date_time":null,"account_id":1,"check_id":1,"check_run_history_id":1,"location_id":1,"image_count":null,"javascript_count":null,"css_count":null,"html_count":null,"flash_count":null,"other_count":null,"run_record_id":null}},"results":[{"key":"har_records","id":"1936"}]}'
|
23
|
+
end
|
24
|
+
|
25
|
+
get '/api/v1/har_records/location_id=1' do
|
26
|
+
'{"count":1,"har_records":{"1939":{"id":"1939","source_url":null,"wait_time":null,"dns_time":null,"send_time":null,"connect_time":null,"blocked_time":null,"receive_time":null,"browser":null,"creator":null,"domain":null,"har_url":"https://s3.amazonaws.com/checkdata.rigor.com/48.harp","entry_count":null,"error_count":null,"dom_load_time":null,"page_load_time":null,"server_time":null,"page_size":null,"client_error_count":null,"server_error_count":null,"connection_error_count":null,"created_at":"2013-12-09T22:40:54Z","updated_at":"2013-12-09T22:40:54Z","started_date_time":null,"account_id":1,"check_id":1,"check_run_history_id":1,"location_id":1,"image_count":null,"javascript_count":null,"css_count":null,"html_count":null,"flash_count":null,"other_count":null,"run_record_id":null}},"results":[{"key":"har_records","id":"1939"}]}'
|
27
|
+
end
|
28
|
+
|
29
|
+
get '/api/v1/har_records' do
|
30
|
+
'{"count":1,"har_records":{"1938":{"id":"1938","source_url":null,"wait_time":null,"dns_time":null,"send_time":null,"connect_time":null,"blocked_time":null,"receive_time":null,"browser":null,"creator":null,"domain":null,"har_url":"https://s3.amazonaws.com/checkdata.rigor.com/47.harp","entry_count":null,"error_count":null,"dom_load_time":null,"page_load_time":null,"server_time":null,"page_size":null,"client_error_count":null,"server_error_count":null,"connection_error_count":null,"created_at":"2013-12-09T22:40:54Z","updated_at":"2013-12-09T22:40:54Z","started_date_time":null,"account_id":1,"check_id":1,"check_run_history_id":1,"location_id":1,"image_count":null,"javascript_count":null,"css_count":null,"html_count":null,"flash_count":null,"other_count":null,"run_record_id":null}},"results":[{"key":"har_records","id":"1938"}]}'
|
31
|
+
end
|
32
|
+
|
33
|
+
get '/api/v1/har_records/per_page=1&page=1' do
|
34
|
+
'{"count":1,"har_records":{"1935":{"id":"1935","source_url":null,"wait_time":null,"dns_time":null,"send_time":null,"connect_time":null,"blocked_time":null,"receive_time":null,"browser":null,"creator":null,"domain":null,"har_url":"https://s3.amazonaws.com/checkdata.rigor.com/44.harp","entry_count":null,"error_count":null,"dom_load_time":null,"page_load_time":null,"server_time":null,"page_size":null,"client_error_count":null,"server_error_count":null,"connection_error_count":null,"created_at":"2013-12-09T22:40:54Z","updated_at":"2013-12-09T22:40:54Z","started_date_time":null,"account_id":1,"check_id":1,"check_run_history_id":1,"location_id":1,"image_count":null,"javascript_count":null,"css_count":null,"html_count":null,"flash_count":null,"other_count":null,"run_record_id":null}},"results":[{"key":"har_records","id":"1935"}]}'
|
35
|
+
end
|
36
|
+
|
37
|
+
post 'api/v1/har_records_bulk' do
|
38
|
+
'{"job_id":"b48c6bd17724fd2324a97f4b"}'
|
39
|
+
end
|
40
|
+
|
41
|
+
delete 'api/v1/har_records_bulk/destroy_by_account_id' do
|
42
|
+
'{"job_id":"997743e056e5d75ef0a142b4"}'
|
43
|
+
end
|
44
|
+
|
45
|
+
delete 'api/v1/har_records_bulk/destroy_by_check_id' do
|
46
|
+
'{"job_id":"d29dcc8754dc997a182f15b5"}'
|
47
|
+
end
|
48
|
+
|
metadata
ADDED
@@ -0,0 +1,195 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dvr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Kyle Conarro
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2013-12-12 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: bundler
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 9
|
29
|
+
segments:
|
30
|
+
- 1
|
31
|
+
- 3
|
32
|
+
version: "1.3"
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rake
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: rspec
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
type: :development
|
62
|
+
version_requirements: *id003
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: pry
|
65
|
+
prerelease: false
|
66
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
hash: 3
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
version: "0"
|
75
|
+
type: :development
|
76
|
+
version_requirements: *id004
|
77
|
+
- !ruby/object:Gem::Dependency
|
78
|
+
name: thor
|
79
|
+
prerelease: false
|
80
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
hash: 3
|
86
|
+
segments:
|
87
|
+
- 0
|
88
|
+
version: "0"
|
89
|
+
type: :runtime
|
90
|
+
version_requirements: *id005
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: json
|
93
|
+
prerelease: false
|
94
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
hash: 3
|
100
|
+
segments:
|
101
|
+
- 0
|
102
|
+
version: "0"
|
103
|
+
type: :runtime
|
104
|
+
version_requirements: *id006
|
105
|
+
- !ruby/object:Gem::Dependency
|
106
|
+
name: sinatra
|
107
|
+
prerelease: false
|
108
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
109
|
+
none: false
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
hash: 3
|
114
|
+
segments:
|
115
|
+
- 0
|
116
|
+
version: "0"
|
117
|
+
type: :runtime
|
118
|
+
version_requirements: *id007
|
119
|
+
description: Mimic your Rails API backend by generating a fake server using recorded HTTP responses
|
120
|
+
email:
|
121
|
+
- kyle.conarro@rigor.com
|
122
|
+
executables:
|
123
|
+
- dvr
|
124
|
+
extensions: []
|
125
|
+
|
126
|
+
extra_rdoc_files: []
|
127
|
+
|
128
|
+
files:
|
129
|
+
- .gitignore
|
130
|
+
- .travis.yml
|
131
|
+
- Gemfile
|
132
|
+
- LICENSE.txt
|
133
|
+
- README.md
|
134
|
+
- Rakefile
|
135
|
+
- bin/dvr
|
136
|
+
- dvr.gemspec
|
137
|
+
- lib/dvr.rb
|
138
|
+
- lib/dvr/cli.rb
|
139
|
+
- lib/dvr/cli/app.rb
|
140
|
+
- lib/dvr/configuration.rb
|
141
|
+
- lib/dvr/episode.rb
|
142
|
+
- lib/dvr/recorder.rb
|
143
|
+
- lib/dvr/season.rb
|
144
|
+
- lib/dvr/version.rb
|
145
|
+
- spec/dvr/configuration_spec.rb
|
146
|
+
- spec/dvr/episode_spec.rb
|
147
|
+
- spec/dvr/recorder_spec.rb
|
148
|
+
- spec/dvr/season_spec.rb
|
149
|
+
- spec/dvr_spec.rb
|
150
|
+
- spec/fixtures/requests/rspec_api_documentation.json
|
151
|
+
- spec/spec_helper.rb
|
152
|
+
- spec/support/server.rb
|
153
|
+
homepage: ""
|
154
|
+
licenses:
|
155
|
+
- MIT
|
156
|
+
post_install_message:
|
157
|
+
rdoc_options: []
|
158
|
+
|
159
|
+
require_paths:
|
160
|
+
- lib
|
161
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
162
|
+
none: false
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
hash: 3
|
167
|
+
segments:
|
168
|
+
- 0
|
169
|
+
version: "0"
|
170
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
171
|
+
none: false
|
172
|
+
requirements:
|
173
|
+
- - ">="
|
174
|
+
- !ruby/object:Gem::Version
|
175
|
+
hash: 3
|
176
|
+
segments:
|
177
|
+
- 0
|
178
|
+
version: "0"
|
179
|
+
requirements: []
|
180
|
+
|
181
|
+
rubyforge_project:
|
182
|
+
rubygems_version: 1.8.15
|
183
|
+
signing_key:
|
184
|
+
specification_version: 3
|
185
|
+
summary: DVR makes it easy to mimic your Rails API backend by generating a fake server using recorded HTTP responses
|
186
|
+
test_files:
|
187
|
+
- spec/dvr/configuration_spec.rb
|
188
|
+
- spec/dvr/episode_spec.rb
|
189
|
+
- spec/dvr/recorder_spec.rb
|
190
|
+
- spec/dvr/season_spec.rb
|
191
|
+
- spec/dvr_spec.rb
|
192
|
+
- spec/fixtures/requests/rspec_api_documentation.json
|
193
|
+
- spec/spec_helper.rb
|
194
|
+
- spec/support/server.rb
|
195
|
+
has_rdoc:
|