emerson 0.1.0.pre.1 → 0.1.0.pre.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -23
- data/.wiprc +0 -0
- data/.yardopts +1 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +177 -0
- data/Rakefile +18 -1
- data/emerson.gemspec +28 -15
- data/lib/emerson.rb +58 -1
- data/lib/emerson/engine.rb +5 -0
- data/lib/emerson/matchers.rb +5 -0
- data/lib/emerson/matchers/action_controller.rb +30 -0
- data/lib/emerson/matchers/action_controller/send_json_matcher.rb +106 -0
- data/lib/emerson/matchers/integrations/rspec.rb +11 -0
- data/lib/emerson/matchers/integrations/test_unit.rb +12 -0
- data/lib/emerson/responder.rb +61 -51
- data/lib/emerson/response.rb +17 -3
- data/lib/emerson/scope.rb +2 -7
- data/lib/emerson/version.rb +1 -1
- data/spec/dummy/README.rdoc +261 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +15 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.gitkeep +0 -0
- data/spec/dummy/app/models/.gitkeep +0 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +65 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +67 -0
- data/spec/dummy/config/environments/test.rb +37 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +15 -0
- data/spec/dummy/config/initializers/jasmine.rb +3 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +6 -0
- data/spec/dummy/lib/assets/.gitkeep +0 -0
- data/spec/dummy/log/.gitkeep +0 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +25 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/dummy/spec/support/fixtures/responses/products/extend-array.json +1 -0
- data/spec/dummy/spec/support/fixtures/responses/products/extend-failure.json +1 -0
- data/spec/dummy/spec/support/fixtures/responses/products/extend-success.json +4 -0
- data/spec/dummy/spec/support/fixtures/responses/products/simple.json +4 -0
- data/spec/emerson/matchers/action_controller/send_json_matcher_spec.rb +126 -0
- data/spec/emerson/responder_spec.rb +222 -0
- data/spec/emerson/response_spec.rb +75 -0
- data/spec/emerson/scope_spec.rb +146 -0
- data/spec/emerson_spec.rb +105 -0
- data/spec/spec_helper.rb +67 -0
- data/spec/support/helpers/controller_helpers.rb +98 -0
- data/spec/support/helpers/feature_helpers.rb +12 -0
- data/spec/support/helpers/resource_helpers.rb +95 -0
- data/spec/support/helpers/template_helpers.rb +31 -0
- data/vendor/assets/javascripts/emerson.js +1 -0
- data/vendor/assets/javascripts/emerson/sink.js +3 -0
- metadata +309 -11
- data/lib/emerson/rails.rb +0 -6
- data/lib/emerson/rails/engine.rb +0 -7
data/.gitignore
CHANGED
@@ -1,24 +1,18 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
coverage
|
10
|
-
doc/
|
11
|
-
lib/bundler/man
|
12
|
-
pkg
|
13
|
-
rdoc
|
14
|
-
spec/reports
|
15
|
-
test/tmp
|
16
|
-
test/version_tmp
|
17
|
-
tmp
|
1
|
+
/.bundle
|
2
|
+
/.env
|
3
|
+
/.gemset
|
4
|
+
/.import
|
5
|
+
/.rvmrc
|
6
|
+
/.rspec
|
7
|
+
/.sublime*
|
8
|
+
/.yardoc
|
18
9
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
10
|
+
/doc/*
|
11
|
+
/log/*.log
|
12
|
+
/pkg/*
|
13
|
+
/tmp/*
|
14
|
+
|
15
|
+
/spec/dummy/db/*.sqlite3
|
16
|
+
/spec/dummy/log/*.log
|
17
|
+
/spec/dummy/tmp/
|
18
|
+
/spec/dummy/.sass-cache
|
data/.wiprc
ADDED
File without changes
|
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--markup markdown --protected --plugin yard-rails lib/**/*.rb - README.md LICENSE
|
data/Gemfile
CHANGED
@@ -2,3 +2,9 @@ source 'https://rubygems.org'
|
|
2
2
|
|
3
3
|
# Specify your gem's dependencies in emerson.gemspec
|
4
4
|
gemspec
|
5
|
+
|
6
|
+
# jquery-rails is used by the dummy application
|
7
|
+
gem "jquery-rails"
|
8
|
+
gem 'jasminerice',
|
9
|
+
:git => 'git://github.com/coreyti/jasminerice.git'
|
10
|
+
gem "jasminerice-runner"
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,177 @@
|
|
1
|
+
GIT
|
2
|
+
remote: git://github.com/coreyti/jasminerice.git
|
3
|
+
revision: 37e379c271cef665d71f54d7dd035687d6377c7d
|
4
|
+
specs:
|
5
|
+
jasminerice (0.0.8)
|
6
|
+
coffee-rails
|
7
|
+
haml
|
8
|
+
|
9
|
+
PATH
|
10
|
+
remote: .
|
11
|
+
specs:
|
12
|
+
emerson (0.1.0.pre.2)
|
13
|
+
jquery-rails
|
14
|
+
rails (>= 3.2.0)
|
15
|
+
|
16
|
+
GEM
|
17
|
+
remote: https://rubygems.org/
|
18
|
+
specs:
|
19
|
+
actionmailer (3.2.8)
|
20
|
+
actionpack (= 3.2.8)
|
21
|
+
mail (~> 2.4.4)
|
22
|
+
actionpack (3.2.8)
|
23
|
+
activemodel (= 3.2.8)
|
24
|
+
activesupport (= 3.2.8)
|
25
|
+
builder (~> 3.0.0)
|
26
|
+
erubis (~> 2.7.0)
|
27
|
+
journey (~> 1.0.4)
|
28
|
+
rack (~> 1.4.0)
|
29
|
+
rack-cache (~> 1.2)
|
30
|
+
rack-test (~> 0.6.1)
|
31
|
+
sprockets (~> 2.1.3)
|
32
|
+
activemodel (3.2.8)
|
33
|
+
activesupport (= 3.2.8)
|
34
|
+
builder (~> 3.0.0)
|
35
|
+
activerecord (3.2.8)
|
36
|
+
activemodel (= 3.2.8)
|
37
|
+
activesupport (= 3.2.8)
|
38
|
+
arel (~> 3.0.2)
|
39
|
+
tzinfo (~> 0.3.29)
|
40
|
+
activeresource (3.2.8)
|
41
|
+
activemodel (= 3.2.8)
|
42
|
+
activesupport (= 3.2.8)
|
43
|
+
activesupport (3.2.8)
|
44
|
+
i18n (~> 0.6)
|
45
|
+
multi_json (~> 1.0)
|
46
|
+
addressable (2.3.2)
|
47
|
+
arel (3.0.2)
|
48
|
+
backports (2.6.4)
|
49
|
+
builder (3.0.4)
|
50
|
+
capybara (1.1.2)
|
51
|
+
mime-types (>= 1.16)
|
52
|
+
nokogiri (>= 1.3.3)
|
53
|
+
rack (>= 1.0.0)
|
54
|
+
rack-test (>= 0.5.4)
|
55
|
+
selenium-webdriver (~> 2.0)
|
56
|
+
xpath (~> 0.1.4)
|
57
|
+
childprocess (0.3.6)
|
58
|
+
ffi (~> 1.0, >= 1.0.6)
|
59
|
+
coffee-rails (3.2.2)
|
60
|
+
coffee-script (>= 2.2.0)
|
61
|
+
railties (~> 3.2.0)
|
62
|
+
coffee-script (2.2.0)
|
63
|
+
coffee-script-source
|
64
|
+
execjs
|
65
|
+
coffee-script-source (1.3.3)
|
66
|
+
diff-lcs (1.1.3)
|
67
|
+
erubis (2.7.0)
|
68
|
+
execjs (1.4.0)
|
69
|
+
multi_json (~> 1.0)
|
70
|
+
ffaker (1.15.0)
|
71
|
+
ffi (1.1.5)
|
72
|
+
haml (3.1.7)
|
73
|
+
hike (1.2.1)
|
74
|
+
i18n (0.6.1)
|
75
|
+
jasmine (1.2.1)
|
76
|
+
jasmine-core (>= 1.2.0)
|
77
|
+
rack (~> 1.0)
|
78
|
+
rspec (>= 1.3.1)
|
79
|
+
selenium-webdriver (>= 0.1.3)
|
80
|
+
jasmine-core (1.2.0)
|
81
|
+
jasminerice-runner (0.0.3)
|
82
|
+
capybara
|
83
|
+
journey (1.0.4)
|
84
|
+
jquery-rails (2.1.3)
|
85
|
+
railties (>= 3.1.0, < 5.0)
|
86
|
+
thor (~> 0.14)
|
87
|
+
json (1.7.5)
|
88
|
+
libwebsocket (0.1.5)
|
89
|
+
addressable
|
90
|
+
mail (2.4.4)
|
91
|
+
i18n (>= 0.4.0)
|
92
|
+
mime-types (~> 1.16)
|
93
|
+
treetop (~> 1.4.8)
|
94
|
+
mime-types (1.19)
|
95
|
+
multi_json (1.3.6)
|
96
|
+
nokogiri (1.5.5)
|
97
|
+
polyglot (0.3.3)
|
98
|
+
rack (1.4.1)
|
99
|
+
rack-cache (1.2)
|
100
|
+
rack (>= 0.4)
|
101
|
+
rack-ssl (1.3.2)
|
102
|
+
rack
|
103
|
+
rack-test (0.6.2)
|
104
|
+
rack (>= 1.0)
|
105
|
+
rails (3.2.8)
|
106
|
+
actionmailer (= 3.2.8)
|
107
|
+
actionpack (= 3.2.8)
|
108
|
+
activerecord (= 3.2.8)
|
109
|
+
activeresource (= 3.2.8)
|
110
|
+
activesupport (= 3.2.8)
|
111
|
+
bundler (~> 1.0)
|
112
|
+
railties (= 3.2.8)
|
113
|
+
railties (3.2.8)
|
114
|
+
actionpack (= 3.2.8)
|
115
|
+
activesupport (= 3.2.8)
|
116
|
+
rack-ssl (~> 1.3.2)
|
117
|
+
rake (>= 0.8.7)
|
118
|
+
rdoc (~> 3.4)
|
119
|
+
thor (>= 0.14.6, < 2.0)
|
120
|
+
rake (0.9.2.2)
|
121
|
+
rdoc (3.12)
|
122
|
+
json (~> 1.4)
|
123
|
+
rspec (2.11.0)
|
124
|
+
rspec-core (~> 2.11.0)
|
125
|
+
rspec-expectations (~> 2.11.0)
|
126
|
+
rspec-mocks (~> 2.11.0)
|
127
|
+
rspec-core (2.11.1)
|
128
|
+
rspec-expectations (2.11.3)
|
129
|
+
diff-lcs (~> 1.1.3)
|
130
|
+
rspec-mocks (2.11.3)
|
131
|
+
rspec-rails (2.11.4)
|
132
|
+
actionpack (>= 3.0)
|
133
|
+
activesupport (>= 3.0)
|
134
|
+
railties (>= 3.0)
|
135
|
+
rspec (~> 2.11.0)
|
136
|
+
rubyzip (0.9.9)
|
137
|
+
selenium-webdriver (2.25.0)
|
138
|
+
childprocess (>= 0.2.5)
|
139
|
+
libwebsocket (~> 0.1.3)
|
140
|
+
multi_json (~> 1.0)
|
141
|
+
rubyzip
|
142
|
+
sprockets (2.1.3)
|
143
|
+
hike (~> 1.2)
|
144
|
+
rack (~> 1.0)
|
145
|
+
tilt (~> 1.1, != 1.3.0)
|
146
|
+
sqlite3 (1.3.6)
|
147
|
+
thor (0.16.0)
|
148
|
+
tilt (1.3.3)
|
149
|
+
treetop (1.4.15)
|
150
|
+
polyglot
|
151
|
+
polyglot (>= 0.3.1)
|
152
|
+
tzinfo (0.3.37)
|
153
|
+
virtus (0.5.2)
|
154
|
+
backports (~> 2.6.1)
|
155
|
+
xpath (0.1.4)
|
156
|
+
nokogiri (~> 1.3)
|
157
|
+
yard (0.8.3)
|
158
|
+
yard-rails (0.3.0)
|
159
|
+
yard
|
160
|
+
|
161
|
+
PLATFORMS
|
162
|
+
ruby
|
163
|
+
|
164
|
+
DEPENDENCIES
|
165
|
+
capybara
|
166
|
+
coffee-script
|
167
|
+
emerson!
|
168
|
+
ffaker
|
169
|
+
jasmine
|
170
|
+
jasminerice!
|
171
|
+
jasminerice-runner
|
172
|
+
jquery-rails
|
173
|
+
rspec-rails
|
174
|
+
sqlite3
|
175
|
+
virtus
|
176
|
+
yard
|
177
|
+
yard-rails
|
data/Rakefile
CHANGED
@@ -1,2 +1,19 @@
|
|
1
1
|
#!/usr/bin/env rake
|
2
|
-
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
exit 1
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'bundler/gem_tasks'
|
10
|
+
require 'rspec/core/rake_task'
|
11
|
+
|
12
|
+
RSpec::Core::RakeTask.new do |t|
|
13
|
+
t.pattern = "spec/**/*_spec.rb"
|
14
|
+
t.rspec_opts = '--color --format progress'
|
15
|
+
t.verbose = false
|
16
|
+
end
|
17
|
+
|
18
|
+
desc 'Default: run specs'
|
19
|
+
task :default => [:spec]
|
data/emerson.gemspec
CHANGED
@@ -1,19 +1,32 @@
|
|
1
|
-
|
2
|
-
require File.expand_path('../lib/emerson/version', __FILE__)
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
2
|
|
4
|
-
|
5
|
-
gem.authors = ["Corey Innis"]
|
6
|
-
gem.email = ["corey@coolerator.net"]
|
7
|
-
gem.description = %q{transcendent views}
|
8
|
-
gem.summary = %q{emerson believes in the inherent good in...}
|
9
|
-
gem.homepage = "https://github.com/coreyti/emerson"
|
3
|
+
require "emerson/version"
|
10
4
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "emerson"
|
7
|
+
s.version = Emerson::VERSION
|
8
|
+
s.authors = ["Corey Innis"]
|
9
|
+
s.email = ["corey@coolerator.net"]
|
10
|
+
s.homepage = "https://github.com/coreyti/emerson"
|
11
|
+
s.summary = %q{transcendent views}
|
12
|
+
s.description = %q{emerson believes in the inherent good in...}
|
17
13
|
|
18
|
-
|
14
|
+
s.files = `git ls-files`.split($\)
|
15
|
+
s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
16
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
17
|
+
|
18
|
+
s.add_dependency "rails", ">= 3.2.0"
|
19
|
+
s.add_dependency "jquery-rails" # for now.
|
20
|
+
|
21
|
+
s.add_development_dependency "capybara"
|
22
|
+
s.add_development_dependency "coffee-script"
|
23
|
+
s.add_development_dependency "ffaker"
|
24
|
+
s.add_development_dependency "jasmine"
|
25
|
+
s.add_development_dependency "jasminerice"
|
26
|
+
s.add_development_dependency "jasminerice-runner"
|
27
|
+
s.add_development_dependency "rspec-rails"
|
28
|
+
s.add_development_dependency "sqlite3"
|
29
|
+
s.add_development_dependency "virtus"
|
30
|
+
s.add_development_dependency "yard"
|
31
|
+
s.add_development_dependency "yard-rails"
|
19
32
|
end
|
data/lib/emerson.rb
CHANGED
@@ -1,8 +1,65 @@
|
|
1
1
|
require "emerson/version"
|
2
|
-
require "emerson/
|
2
|
+
require "emerson/engine"
|
3
3
|
|
4
4
|
module Emerson
|
5
5
|
autoload :Responder, 'emerson/responder'
|
6
6
|
autoload :Response, 'emerson/response'
|
7
7
|
autoload :Scope, 'emerson/scope'
|
8
|
+
|
9
|
+
# Hook for enabling a specific set of Emerson "features".
|
10
|
+
#
|
11
|
+
# @note The disabling arguments (`nil`, `false`) are included for
|
12
|
+
# completeness. A better way to disable Emerson features would be to
|
13
|
+
# **not** include `Emerson::Response` in your controller(s).
|
14
|
+
#
|
15
|
+
# @param value [Array, Symbol, false, nil] The list of features,
|
16
|
+
# `:all` (default), `nil` or `false` (to disable completely).
|
17
|
+
mattr_accessor :features
|
18
|
+
@@features = :all
|
19
|
+
|
20
|
+
# Custom path for fixture files.
|
21
|
+
#
|
22
|
+
# @note This attribute **must** be set in order to use the included response
|
23
|
+
# matchers. If RSpec fixtures are disabled, be sure to enable specifically
|
24
|
+
# for Emerson.
|
25
|
+
#
|
26
|
+
# @param value [String] The path. Defaults to RSpec's `fixture_path`.
|
27
|
+
mattr_accessor :fixture_path
|
28
|
+
@@fixture_path = nil
|
29
|
+
|
30
|
+
mattr_accessor :response_config
|
31
|
+
@@response_config = {
|
32
|
+
:json_default => 'full'
|
33
|
+
}
|
34
|
+
|
35
|
+
# Default way to setup Emerson. For Rails, call from an initializer.
|
36
|
+
#
|
37
|
+
# @example in 'config/initializers/emerson.rb'
|
38
|
+
# Emerson.setup do |config|
|
39
|
+
# config.fixture_path = Rails.root.join('custom/path')
|
40
|
+
# end
|
41
|
+
def self.setup
|
42
|
+
# environmental defaults:
|
43
|
+
if defined?(RSpec)
|
44
|
+
self.fixture_path ||= RSpec.configuration.fixture_path
|
45
|
+
end
|
46
|
+
|
47
|
+
yield self
|
48
|
+
end
|
49
|
+
|
50
|
+
# Helper to determine whether `Emerson::Responder` is enabled.
|
51
|
+
def self.responder_enabled?
|
52
|
+
self.feature_enabled?(:responder)
|
53
|
+
end
|
54
|
+
|
55
|
+
# Helper to determine whether `Emerson::Scope` is enabled.
|
56
|
+
def self.scope_enabled?
|
57
|
+
self.feature_enabled?(:scope)
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def self.feature_enabled?(key)
|
63
|
+
self.features.present? && (self.features == :all || self.features.include?(key))
|
64
|
+
end
|
8
65
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# require 'emerson/matchers/action_controller/send_html_matcher'
|
2
|
+
require 'emerson/matchers/action_controller/send_json_matcher'
|
3
|
+
|
4
|
+
module Emerson
|
5
|
+
module Matchers
|
6
|
+
# By using the matchers you can quickly and easily create concise and
|
7
|
+
# easy to read test suites.
|
8
|
+
#
|
9
|
+
# This code segment:
|
10
|
+
#
|
11
|
+
# describe UsersController, "on GET to show with a valid id" do
|
12
|
+
# before(:each) do
|
13
|
+
# get :show, :id => User.first.to_param
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# it { should assign_to(:user) }
|
17
|
+
# it { should respond_with(:success) }
|
18
|
+
# it { should render_template(:show) }
|
19
|
+
# it { should not_set_the_flash) }
|
20
|
+
#
|
21
|
+
# it "should do something else really cool" do
|
22
|
+
# assigns[:user].id.should == 1
|
23
|
+
# end
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
# Would produce 5 tests for the show action
|
27
|
+
module ActionController
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
module Emerson
|
2
|
+
module Matchers
|
3
|
+
module ActionController
|
4
|
+
# Example:
|
5
|
+
#
|
6
|
+
# expect(response).to send_json({ :key => 'value' })
|
7
|
+
# expect(response).to send_json('path/to/fixture')
|
8
|
+
#
|
9
|
+
# Example fixture definitions:
|
10
|
+
#
|
11
|
+
# # 'data-fixture.json'
|
12
|
+
# {
|
13
|
+
# "data" : {
|
14
|
+
# "user" : 1
|
15
|
+
# }
|
16
|
+
# }
|
17
|
+
#
|
18
|
+
# # 'view-fixture.json'
|
19
|
+
# {
|
20
|
+
# "view" : "<article class=\"user\"></article>"
|
21
|
+
# }
|
22
|
+
#
|
23
|
+
# # 'full-fixture.json' (will merge data & view)
|
24
|
+
# {
|
25
|
+
# "$extends" : ["data-fixture.json", "view-fixture.json"]
|
26
|
+
# }
|
27
|
+
def send_json(expected)
|
28
|
+
SendJsonMatcher.new(expected, self)
|
29
|
+
end
|
30
|
+
|
31
|
+
class SendJsonMatcher
|
32
|
+
attr_reader :expected, :actual, :mode
|
33
|
+
|
34
|
+
def initialize(expected, context)
|
35
|
+
@context = context
|
36
|
+
@expected = prepare(expected)
|
37
|
+
end
|
38
|
+
|
39
|
+
def description
|
40
|
+
['send JSON:', @mode_description].join(' ')
|
41
|
+
end
|
42
|
+
|
43
|
+
def matches?(response)
|
44
|
+
@actual = JSON.parse(response.body)
|
45
|
+
actual == expected
|
46
|
+
end
|
47
|
+
|
48
|
+
def failure_message
|
49
|
+
msg = <<-MSG
|
50
|
+
Expected actual response:
|
51
|
+
#{'-' * 60}
|
52
|
+
#{JSON.pretty_generate(actual)}
|
53
|
+
to match:
|
54
|
+
#{'-' * 60}
|
55
|
+
#{JSON.pretty_generate(expected)}
|
56
|
+
MSG
|
57
|
+
|
58
|
+
msg.gsub(/^\s{12}/, '')
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def filename(name)
|
64
|
+
"#{name.sub(/\.json\z/, '')}.json"
|
65
|
+
end
|
66
|
+
|
67
|
+
def fixture(name)
|
68
|
+
File.join(fixture_path, filename(name))
|
69
|
+
end
|
70
|
+
|
71
|
+
# TODO: allow Test::Unit definition
|
72
|
+
def fixture_path
|
73
|
+
# @_fixture_path ||= "#{Emerson.fixture_path || RSpec.configuration.fixture_path}/responses"
|
74
|
+
@_fixture_path ||= File.join(Emerson.fixture_path, 'responses')
|
75
|
+
end
|
76
|
+
|
77
|
+
def prepare(source)
|
78
|
+
result = begin
|
79
|
+
case source
|
80
|
+
when String
|
81
|
+
@mode_description = filename(source)
|
82
|
+
path = fixture(source)
|
83
|
+
File.exist?(path) ? JSON.parse(File.read(path)) : { :missing => path.to_s }
|
84
|
+
when Array, Hash
|
85
|
+
@mode_description = '(provided)'
|
86
|
+
JSON.parse(source.to_json)
|
87
|
+
else
|
88
|
+
raise ArgumentError.new('expected "JSON" should be a Hash, or a String lookup')
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
if result.is_a?(Hash) && result.keys.include?('$extends')
|
93
|
+
refs = [result.delete('$extends')].flatten
|
94
|
+
|
95
|
+
result = {}.tap do |hash|
|
96
|
+
refs.each { |ref| hash.merge!(prepare(ref)) }
|
97
|
+
hash.merge!(result)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
result
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|