stub-hub 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 38c1d4d2c48e51577b3d10ad820861938114dbed
4
+ data.tar.gz: f47da1ffc17e616272bcaae21e117b0c60facce7
5
+ SHA512:
6
+ metadata.gz: 0149920ef49c4556889d8556e70bacadc05de18bd7688f86618ddd457b6fd22bd064dc8272fc5a0097438a7c732b872464a78e26e330d89871f4e8e34be569e4
7
+ data.tar.gz: ce002b950a9863ba08bd407c62fd5c49fa09c502d1280c87316c2424663e92abcdce2a20b2622e30b731ce87d2b44ef99733dd71b9f87b69fc744f3872835a11
@@ -0,0 +1,17 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+
16
+ # OSX
17
+ *.DS_Store
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -0,0 +1 @@
1
+ stub-hub
@@ -0,0 +1 @@
1
+ ruby-2.0.0-p576
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in stub-hub.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Edward Huynh
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.
@@ -0,0 +1,51 @@
1
+ # Stubhub
2
+
3
+ Stub an endpoint.
4
+
5
+ Stubhub helps with developing against an endpoint.
6
+ Use stubbed responses to develop against and you will not have to rely on an endpoint
7
+ that might be a tad unstable.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'stub-hub'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install stub-hub
24
+
25
+ ## Quickstart
26
+
27
+ Starting the stub server with the seed directory as the current directory:
28
+
29
+ $ stubhub start
30
+
31
+ Starting the stub server with a differnt seed directory
32
+
33
+ $ stubhub start -s "~/path/to/seed/dir"
34
+
35
+ ## Stub files
36
+
37
+ The stub files are matched to the URIs as follows:
38
+
39
+ | uri path | matched file name |
40
+ | ------------------- | ------------------- |
41
+ | /resource | resource |
42
+ | /resource.json | resource.json |
43
+ | /path/to/resource | path-to-resource |
44
+
45
+ ## Contributing
46
+
47
+ 1. Fork it ( https://github.com/[my-github-username]/stub-hub/fork )
48
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
49
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
50
+ 4. Push to the branch (`git push origin my-new-feature`)
51
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'stub-hub'
4
+
5
+ Stubhub::CLI.start
@@ -0,0 +1,2 @@
1
+ require 'rubygems'
2
+ require 'stub-hub/cli'
@@ -0,0 +1,22 @@
1
+ require 'rack'
2
+ require 'stub-hub/file_store'
3
+
4
+ module Stubhub
5
+ class App
6
+ attr_accessor :file_store
7
+
8
+ def initialize(seed_directory)
9
+ @file_store = FileStore.new(seed_directory)
10
+ end
11
+
12
+ def call(env)
13
+ req = Rack::Request.new env
14
+ stub_response = @file_store.file_for_uri req.path_info
15
+ if !stub_response.empty?
16
+ [200, {"Content-Type" => "text/json"}, [stub_response.contents]]
17
+ else
18
+ [404, {}, [""]]
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,16 @@
1
+ require 'rack'
2
+ require 'thor'
3
+ require 'stub-hub/app'
4
+
5
+ module Stubhub
6
+ class CLI < Thor
7
+ desc "start", "Starts the server"
8
+ method_option :"seed-dir", :aliases => "-s", :desc => "path to directory which contains the stub content"
9
+ def start
10
+ seed_directory = options[:"seed-dir"] ? options[:"seed-dir"] : "."
11
+ Rack::Server.start(
12
+ :app => Stubhub::App.new(seed_directory)
13
+ )
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,37 @@
1
+ require 'rubygems'
2
+
3
+ module Stubhub
4
+ StubResponse = Struct.new(:contents) do
5
+
6
+ def empty?
7
+ contents == nil
8
+ end
9
+
10
+ def self.empty_response
11
+ self.new
12
+ end
13
+
14
+ end
15
+
16
+ class FileStore
17
+
18
+ def initialize(seed_directory)
19
+ @seed_directory = File.expand_path(seed_directory)
20
+ end
21
+
22
+ def file_for_uri uri
23
+ file_name = translate_uri_to_file_name uri
24
+ file_path = File.join(@seed_directory, file_name)
25
+ if File.exists?(file_path)
26
+ contents = File.open(file_path, "r").read
27
+ StubResponse.new(contents)
28
+ else
29
+ StubResponse.empty_response
30
+ end
31
+ end
32
+
33
+ def translate_uri_to_file_name uri
34
+ uri.sub(/^\//, "").gsub(/\//, "-")
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,3 @@
1
+ module Stubhub
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,89 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
4
+ # file to always be loaded, without a need to explicitly require it in any files.
5
+ #
6
+ # Given that it is always loaded, you are encouraged to keep this file as
7
+ # light-weight as possible. Requiring heavyweight dependencies from this file
8
+ # will add to the boot time of your test suite on EVERY test run, even for an
9
+ # individual file that may not need all of that loaded. Instead, consider making
10
+ # a separate helper file that requires the additional dependencies and performs
11
+ # the additional setup, and require it from the spec files that actually need it.
12
+ #
13
+ # The `.rspec` file also contains a few flags that are not defaults but that
14
+ # users commonly want.
15
+ #
16
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
17
+ RSpec.configure do |config|
18
+ # rspec-expectations config goes here. You can use an alternate
19
+ # assertion/expectation library such as wrong or the stdlib/minitest
20
+ # assertions if you prefer.
21
+ config.expect_with :rspec do |expectations|
22
+ # This option will default to `true` in RSpec 4. It makes the `description`
23
+ # and `failure_message` of custom matchers include text for helper methods
24
+ # defined using `chain`, e.g.:
25
+ # be_bigger_than(2).and_smaller_than(4).description
26
+ # # => "be bigger than 2 and smaller than 4"
27
+ # ...rather than:
28
+ # # => "be bigger than 2"
29
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
30
+ end
31
+
32
+ # rspec-mocks config goes here. You can use an alternate test double
33
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
34
+ config.mock_with :rspec do |mocks|
35
+ # Prevents you from mocking or stubbing a method that does not exist on
36
+ # a real object. This is generally recommended, and will default to
37
+ # `true` in RSpec 4.
38
+ mocks.verify_partial_doubles = true
39
+ end
40
+
41
+ # The settings below are suggested to provide a good initial experience
42
+ # with RSpec, but feel free to customize to your heart's content.
43
+ =begin
44
+ # These two settings work together to allow you to limit a spec run
45
+ # to individual examples or groups you care about by tagging them with
46
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
47
+ # get run.
48
+ config.filter_run :focus
49
+ config.run_all_when_everything_filtered = true
50
+
51
+ # Limits the available syntax to the non-monkey patched syntax that is recommended.
52
+ # For more details, see:
53
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
54
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
55
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
56
+ config.disable_monkey_patching!
57
+
58
+ # This setting enables warnings. It's recommended, but in some cases may
59
+ # be too noisy due to issues in dependencies.
60
+ config.warnings = true
61
+
62
+ # Many RSpec users commonly either run the entire suite or an individual
63
+ # file, and it's useful to allow more verbose output when running an
64
+ # individual spec file.
65
+ if config.files_to_run.one?
66
+ # Use the documentation formatter for detailed output,
67
+ # unless a formatter has already been configured
68
+ # (e.g. via a command-line flag).
69
+ config.default_formatter = 'doc'
70
+ end
71
+
72
+ # Print the 10 slowest examples and example groups at the
73
+ # end of the spec run, to help surface which specs are running
74
+ # particularly slow.
75
+ config.profile_examples = 10
76
+
77
+ # Run specs in random order to surface order dependencies. If you find an
78
+ # order dependency and want to debug it, you can fix the order by providing
79
+ # the seed, which is printed after each run.
80
+ # --seed 1234
81
+ config.order = :random
82
+
83
+ # Seed global randomization in this process using the `--seed` CLI option.
84
+ # Setting this allows you to use `--seed` to deterministically reproduce
85
+ # test failures related to randomization by passing the same `--seed` value
86
+ # as the one that triggered the failure.
87
+ Kernel.srand config.seed
88
+ =end
89
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ require 'stub-hub/app'
4
+ require 'fakefs/spec_helpers'
5
+ require "rack/test"
6
+
7
+ describe Stubhub::App do
8
+
9
+ include FakeFS::SpecHelpers
10
+ include Rack::Test::Methods
11
+
12
+ def app
13
+ Stubhub::App.new(".")
14
+ end
15
+
16
+ it "returns not found if stubbed response does not exist" do
17
+ get "/test"
18
+ expect(last_response).to be_not_found
19
+ end
20
+
21
+ it "returns a successful stubbed response if one exists" do
22
+ File.write("test", "hello world")
23
+ get "/test"
24
+ expect(last_response).to be_ok
25
+ expect(last_response.body).to eq("hello world")
26
+ end
27
+
28
+ end
@@ -0,0 +1,72 @@
1
+ require 'spec_helper'
2
+
3
+ require 'stub-hub/file_store'
4
+ require 'fakefs/spec_helpers'
5
+
6
+ describe Stubhub::FileStore do
7
+
8
+ include FakeFS::SpecHelpers
9
+
10
+ context "finding stub file" do
11
+
12
+ before do
13
+ @fs = Stubhub::FileStore.new(".")
14
+ end
15
+
16
+ it "returns an empty stubbed response if no matching stub file found" do
17
+ response = @fs.file_for_uri("test")
18
+ expect(response).to be_empty
19
+ end
20
+
21
+ context "path with one segment" do
22
+
23
+ before do
24
+ @uri = "/test"
25
+ end
26
+
27
+ it "returns the stubbed response of the stub file where the file name matches the path" do
28
+ File.write("test", "hello world")
29
+ fs = Stubhub::FileStore.new(".")
30
+ response = fs.file_for_uri(@uri)
31
+ expect(response.contents).to eq("hello world")
32
+ end
33
+
34
+ end
35
+
36
+ context "path with more than one segment" do
37
+
38
+ before do
39
+ @uri = "/path/to/resource"
40
+ end
41
+
42
+ it "returns the stubbed response of the stub file where the file name matches the path where / are replaced by -" do
43
+ File.write("path-to-resource", "hello world")
44
+ fs = Stubhub::FileStore.new(".")
45
+ response = fs.file_for_uri(@uri)
46
+ expect(response.contents).to eq("hello world")
47
+ end
48
+ end
49
+
50
+ end
51
+
52
+ context "seed directory" do
53
+
54
+ before do
55
+ File.write("test", "hello world")
56
+ end
57
+
58
+ it "can set the seed directory with a relative path" do
59
+ fs = Stubhub::FileStore.new(".")
60
+ response = fs.file_for_uri("test")
61
+ expect(response.contents).to eq("hello world")
62
+ end
63
+
64
+ it "can set the seed directory with an absolute path" do
65
+ fs = Stubhub::FileStore.new(Dir.getwd)
66
+ response = fs.file_for_uri("test")
67
+ expect(response.contents).to eq("hello world")
68
+ end
69
+
70
+ end
71
+
72
+ end
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'stub-hub/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "stub-hub"
8
+ spec.version = Stubhub::VERSION
9
+ spec.authors = ["Edward Huynh"]
10
+ spec.email = ["edward@edwardhuynh.com"]
11
+ spec.summary = %q{Stub an endpoint.}
12
+ spec.description = %q{StubHub helps with developing against an endpoint.
13
+ Use stubbed responses to develop against and you will not have to rely on an endpoint
14
+ that might be a tad unstable. }
15
+ spec.homepage = ""
16
+ spec.license = "MIT"
17
+
18
+ spec.files = `git ls-files -z`.split("\x0")
19
+ spec.executables << 'stubhub'
20
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.7"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.1.0"
26
+ spec.add_development_dependency "fakefs", "~> 0.6.0"
27
+ spec.add_development_dependency "rack-test", "~> 0.6.2"
28
+ spec.add_development_dependency "byebug", "~> 3.5.1"
29
+
30
+ spec.add_runtime_dependency "thor", "~> 0.19"
31
+ spec.add_runtime_dependency "rack", "~> 1.5"
32
+ end
metadata ADDED
@@ -0,0 +1,180 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stub-hub
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Edward Huynh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 3.1.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 3.1.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: fakefs
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.6.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 0.6.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: rack-test
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 0.6.2
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 0.6.2
83
+ - !ruby/object:Gem::Dependency
84
+ name: byebug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: 3.5.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: 3.5.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: thor
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: '0.19'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: '0.19'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rack
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: '1.5'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ~>
123
+ - !ruby/object:Gem::Version
124
+ version: '1.5'
125
+ description: "StubHub helps with developing against an endpoint.\n Use
126
+ stubbed responses to develop against and you will not have to rely on an endpoint\n
127
+ \ that might be a tad unstable. "
128
+ email:
129
+ - edward@edwardhuynh.com
130
+ executables:
131
+ - stubhub
132
+ extensions: []
133
+ extra_rdoc_files: []
134
+ files:
135
+ - .gitignore
136
+ - .rspec
137
+ - .ruby-gemset
138
+ - .ruby-version
139
+ - Gemfile
140
+ - LICENSE.txt
141
+ - README.md
142
+ - Rakefile
143
+ - bin/stubhub
144
+ - lib/stub-hub.rb
145
+ - lib/stub-hub/app.rb
146
+ - lib/stub-hub/cli.rb
147
+ - lib/stub-hub/file_store.rb
148
+ - lib/stub-hub/version.rb
149
+ - spec/spec_helper.rb
150
+ - spec/stubhub/app_spec.rb
151
+ - spec/stubhub/file_store_spec.rb
152
+ - stub-hub.gemspec
153
+ homepage: ''
154
+ licenses:
155
+ - MIT
156
+ metadata: {}
157
+ post_install_message:
158
+ rdoc_options: []
159
+ require_paths:
160
+ - lib
161
+ required_ruby_version: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - '>='
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ required_rubygems_version: !ruby/object:Gem::Requirement
167
+ requirements:
168
+ - - '>='
169
+ - !ruby/object:Gem::Version
170
+ version: '0'
171
+ requirements: []
172
+ rubyforge_project:
173
+ rubygems_version: 2.2.2
174
+ signing_key:
175
+ specification_version: 4
176
+ summary: Stub an endpoint.
177
+ test_files:
178
+ - spec/spec_helper.rb
179
+ - spec/stubhub/app_spec.rb
180
+ - spec/stubhub/file_store_spec.rb