holla_back 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.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/Guardfile +16 -0
- data/LICENSE.txt +22 -0
- data/README.md +115 -0
- data/Rakefile +29 -0
- data/VERSION +1 -0
- data/holla_back.gemspec +38 -0
- data/lib/holla_back.rb +20 -0
- data/lib/holla_back/option_loader.rb +39 -0
- data/lib/holla_back/response.rb +100 -0
- data/test/support/.gitkeep +0 -0
- data/test/test_helper.rb +31 -0
- data/test/unit/holla_back/option_loader_test.rb +21 -0
- data/test/unit/holla_back/response_test.rb +88 -0
- data/test/unit/holla_back_test.rb +17 -0
- metadata +320 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4ccaa754e972d5506f0559b10564e8685e601fce
|
4
|
+
data.tar.gz: 163b69aa7405593d6ca55330fa2ee99dd5dbedcb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 00594d4f2e7b168846de8365ae2ad27f8f4880eae097dad9733bb78151986fa576065ef9cfdebcbe13dc4cb34da2c744482020d3858766717e50903c542e8d2d
|
7
|
+
data.tar.gz: e4888389ef496d624db493feb8c863764696e62fab5f9d498213b168864d35223f0a17b686a1cad84690e83b42fba586eaf7a2f05254e068a6404d30d369a075
|
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm 2.0.0@holla_back_gem --create
|
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
notification :libnotify
|
5
|
+
|
6
|
+
guard 'minitest' do
|
7
|
+
# with Minitest::Unit
|
8
|
+
watch(%r|^test/(.*)_test\.rb|)
|
9
|
+
watch(%r|^lib/(.*)/([^/]+)\.rb|) { |m| "test/unit/#{m[1]}/#{m[2]}_test.rb" }
|
10
|
+
watch(%r|^test/test_helper\.rb|) { "test" }
|
11
|
+
|
12
|
+
# with Minitest::Spec
|
13
|
+
# watch(%r|^spec/(.*)_spec\.rb|)
|
14
|
+
# watch(%r|^lib/(.*)\.rb|) { |m| "spec/#{m[1]}_spec.rb" }
|
15
|
+
# watch(%r|^spec/spec_helper\.rb|) { "spec" }
|
16
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 David Chapman
|
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,115 @@
|
|
1
|
+
# Holla Back!
|
2
|
+
|
3
|
+
HollaBack is a simple Ruby gem that will provide a standard for responses
|
4
|
+
in your classes/modules, and it can be configured with extra options for
|
5
|
+
custom status messages, and methods that will be ran so that information
|
6
|
+
from those methods can be included in your response object.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'holla_back'
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install holla_back
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
Ponder the hypothetical class with HollaBack included that will be used for these examples as defined below:
|
25
|
+
|
26
|
+
> `some_class.rb`
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
class SomeClass
|
30
|
+
include HollaBack
|
31
|
+
|
32
|
+
def truthy_method
|
33
|
+
true
|
34
|
+
end
|
35
|
+
|
36
|
+
def falsey_method
|
37
|
+
[nil, false].sample
|
38
|
+
end
|
39
|
+
|
40
|
+
def conditional_method_with_params(condition=nil)
|
41
|
+
condition ? true : false
|
42
|
+
end
|
43
|
+
|
44
|
+
def info_method
|
45
|
+
'some random info'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
```
|
49
|
+
|
50
|
+
Simple example:
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
klass = SomeClass.new
|
54
|
+
|
55
|
+
# Minimal request
|
56
|
+
response = klass.response(status_method: 'truthy_method')
|
57
|
+
# => #<HollaBack::Response>
|
58
|
+
response.successful?
|
59
|
+
# => true
|
60
|
+
response.status_message
|
61
|
+
# => "Status: successful"
|
62
|
+
```
|
63
|
+
|
64
|
+
With customized status messages:
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
# If we have a truthy status method
|
68
|
+
response = klass.response(status_method: 'truthy_method', success_message: "It worked! :D", failure_message: "It didn't work! D:")
|
69
|
+
# => #<HollaBack::Response>
|
70
|
+
response.successful?
|
71
|
+
# => true
|
72
|
+
response.status_message
|
73
|
+
# => "It worked! :D"
|
74
|
+
|
75
|
+
# If we have a falsy status method
|
76
|
+
response = klass.response(status_method: 'falsey_method', success_message: "It worked! :D", failure_message: "It didn't work! D:")
|
77
|
+
# => #<HollaBack::Response>
|
78
|
+
response.successful?
|
79
|
+
# => false
|
80
|
+
response.status_message
|
81
|
+
# => "It didn't work! D:"
|
82
|
+
```
|
83
|
+
With extra methods you need information from
|
84
|
+
|
85
|
+
```ruby
|
86
|
+
response = klass.response(status_method: 'falsey_method', responding_methods: [:optional_method, {:optional_method_with_params => ['some param']}])
|
87
|
+
# => #<HollaBack::Response>
|
88
|
+
response.responding_methods
|
89
|
+
#=> {:optional_method=>"this was only optional", :optional_method_with_params=>true}
|
90
|
+
```
|
91
|
+
|
92
|
+
If you pass in a status method or some responding methods that raise exceptions, HollaBack will
|
93
|
+
simply handle these gracefully, because exceptions are still a response from your code. The important
|
94
|
+
one is your status message. If you want to force the error, then you call the `successful?` to force
|
95
|
+
the exception on the status method, else you can check the responding object for the Exception.
|
96
|
+
|
97
|
+
With some method that totally doesn't exist
|
98
|
+
|
99
|
+
```ruby
|
100
|
+
response = klass.response(status_method: 'some_method_that_totally_doesnt_exist')
|
101
|
+
# => #<HollaBack::Response>
|
102
|
+
response.responding_object
|
103
|
+
#=> NoMethodError
|
104
|
+
response.status_message
|
105
|
+
#=> "undefined method `some_method_that_totally_doesnt_exist' for #<SomeClass:0x00000001e1b008>"
|
106
|
+
```
|
107
|
+
|
108
|
+
|
109
|
+
## Contributing
|
110
|
+
|
111
|
+
1. Fork it
|
112
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
113
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
114
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
115
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require 'rake/testtask'
|
3
|
+
|
4
|
+
Rake::TestTask.new do |t|
|
5
|
+
t.libs << 'lib'
|
6
|
+
t.libs << 'test'
|
7
|
+
t.pattern = 'test/**/*_test.rb'
|
8
|
+
end
|
9
|
+
|
10
|
+
require 'rake/version_task'
|
11
|
+
Rake::VersionTask.new do |task|
|
12
|
+
task.with_git_tag = true
|
13
|
+
end
|
14
|
+
|
15
|
+
### DOCUMENTATION METRICS ###
|
16
|
+
# measure coverage
|
17
|
+
require 'yardstick/rake/measurement'
|
18
|
+
Yardstick::Rake::Measurement.new(:yardstick_measure) do |measurement|
|
19
|
+
measurement.output = 'measurement/report.txt'
|
20
|
+
measurement.path = ['lib/**/*.rb', 'app/**/*.rb']
|
21
|
+
end
|
22
|
+
|
23
|
+
# verify coverage
|
24
|
+
require 'yardstick/rake/verify'
|
25
|
+
Yardstick::Rake::Verify.new do |verify|
|
26
|
+
verify.threshold = 95
|
27
|
+
verify.require_exact_threshold = false
|
28
|
+
verify.path = ['lib/**/*.rb']
|
29
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/holla_back.gemspec
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.name = "holla_back"
|
7
|
+
gem.version = `cat VERSION`.strip
|
8
|
+
gem.authors = ["David Chapman"]
|
9
|
+
gem.email = ["david@isotope11.com"]
|
10
|
+
gem.description = %q{A simple Ruby gem for providing a response standard to your libraries}
|
11
|
+
gem.summary = %q{HollaBack will simply provide a unified response object containing needed information and responses.}
|
12
|
+
gem.homepage = ""
|
13
|
+
gem.license = "MIT"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|gem|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_development_dependency "bundler", "~> 1.3"
|
21
|
+
gem.add_development_dependency "rake"
|
22
|
+
gem.add_development_dependency 'minitest'
|
23
|
+
gem.add_development_dependency 'minitest-matchers'
|
24
|
+
gem.add_development_dependency 'minitest-reporters'
|
25
|
+
gem.add_development_dependency 'pry'
|
26
|
+
gem.add_development_dependency 'rake'
|
27
|
+
gem.add_development_dependency 'simplecov'
|
28
|
+
gem.add_development_dependency 'simplecov-rcov'
|
29
|
+
gem.add_development_dependency 'yard'
|
30
|
+
gem.add_development_dependency 'yardstick'
|
31
|
+
gem.add_development_dependency 'redcarpet'
|
32
|
+
gem.add_development_dependency 'guard-minitest'
|
33
|
+
gem.add_development_dependency 'libnotify'
|
34
|
+
gem.add_development_dependency 'mocha'
|
35
|
+
gem.add_development_dependency 'version'
|
36
|
+
gem.add_development_dependency 'turn'
|
37
|
+
gem.add_development_dependency 'ansi'
|
38
|
+
end
|
data/lib/holla_back.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative "../lib/holla_back/response"
|
2
|
+
require_relative "../lib/holla_back/option_loader"
|
3
|
+
|
4
|
+
# The main HollaBack module that all objects inherit from
|
5
|
+
module HollaBack
|
6
|
+
# Callback invoked to define the response method in the including object
|
7
|
+
# @example
|
8
|
+
# class SomeClass; include HollaBack; end
|
9
|
+
#
|
10
|
+
# @param [Object] obj - the object that included HollaBack
|
11
|
+
# @return [HollaBack::Response] - a new HollaBack::Response object
|
12
|
+
# @api public
|
13
|
+
def HollaBack.included(obj)
|
14
|
+
obj.instance_eval do
|
15
|
+
define_method(:response) { |responding_obj=self, options|
|
16
|
+
HollaBack::Response.new(responding_obj, options)
|
17
|
+
}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module HollaBack
|
2
|
+
# Module of methods for loading options
|
3
|
+
module OptionLoader
|
4
|
+
# Loads one option into an instance variable and raises if it's missing the option
|
5
|
+
#
|
6
|
+
# @example
|
7
|
+
# load_option('foo', {:foo => 'bar'})
|
8
|
+
# @foo #=> 'bar'
|
9
|
+
#
|
10
|
+
# @param [String] option the name of the instance variable you want
|
11
|
+
# @param [Hash] options the hash of options to fetch the value of the instance variable
|
12
|
+
# @return [Class] the class type of the fetchted value in the options hash
|
13
|
+
# @return [Exception] an exception will be raised if the option isn't found in the options hash
|
14
|
+
# @api public
|
15
|
+
def load_option(option, options)
|
16
|
+
instance_variable_set("@#{option}", options.fetch(option.to_sym) { raise "Missing required option: #{option}" } )
|
17
|
+
end
|
18
|
+
|
19
|
+
# Loads multiple options in an array from an options hash
|
20
|
+
#
|
21
|
+
# @example
|
22
|
+
# load_options({:foo1 => 'bar1', :foo2 => 'bar2'}, :foo1, :foo2)
|
23
|
+
# @foo1 #=> 'bar1'
|
24
|
+
# @foo2 #=> 'bar2'
|
25
|
+
#
|
26
|
+
#
|
27
|
+
# @param [Array] option_names the array of option names to fetch from the options hash
|
28
|
+
# @param [Hash] options the hash of options which hold values for each option name
|
29
|
+
# @return [Class] the class type of the fetched value in the options hash
|
30
|
+
# @return [Exception] an exception will be raised if the option isn't found in the options hash
|
31
|
+
# @see #load_option
|
32
|
+
# @api public
|
33
|
+
def load_options(options, *option_names)
|
34
|
+
option_names.each{|o| load_option(o, options) }
|
35
|
+
end
|
36
|
+
|
37
|
+
module_function :load_option, :load_options
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require_relative "../holla_back/option_loader.rb"
|
2
|
+
module HollaBack
|
3
|
+
# The main class for providing response objects
|
4
|
+
class Response
|
5
|
+
include HollaBack::OptionLoader
|
6
|
+
# @return [Object] responding_object - The responding object
|
7
|
+
# @api public
|
8
|
+
attr_accessor :responding_object
|
9
|
+
# @return [Hash] responding_methods - The hash of key (method) value (return) pairs
|
10
|
+
attr_accessor :responding_methods
|
11
|
+
# @return [String] status_message - The status message for the response
|
12
|
+
attr_accessor :status_message
|
13
|
+
|
14
|
+
# A new instance of HollaBack::Response
|
15
|
+
#
|
16
|
+
# @example
|
17
|
+
# response = HollaBack::Response.new({responding_object: SomeObject.new, status_message: 'valid?'})
|
18
|
+
#
|
19
|
+
# @param [Hash] options - a hash of options
|
20
|
+
# @param [Object] responding_obj - the object responsible for determining a response
|
21
|
+
# @return [Response] the new response object
|
22
|
+
# @api public
|
23
|
+
def initialize(responding_obj=nil, options)
|
24
|
+
options = {
|
25
|
+
responding_methods: [],
|
26
|
+
success_message: nil,
|
27
|
+
failure_message: nil
|
28
|
+
}.merge(options)
|
29
|
+
load_options(options, :responding_methods, :status_method, :success_message, :failure_message)
|
30
|
+
self.responding_object = responding_obj
|
31
|
+
set_response!
|
32
|
+
end
|
33
|
+
|
34
|
+
# The status of success
|
35
|
+
#
|
36
|
+
# @example
|
37
|
+
# response.success? #=> true
|
38
|
+
#
|
39
|
+
# @return [Boolean] true - if the status method is not nil or false
|
40
|
+
# @return [Boolean] false - if the status method is nil or false
|
41
|
+
# @api public
|
42
|
+
def successful?
|
43
|
+
!!@responding_object.send(@status_method)
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
# Sets the response attributes
|
48
|
+
#
|
49
|
+
# @example
|
50
|
+
# response.set_response! #=> #<HollaBack::Response>
|
51
|
+
#
|
52
|
+
# @return [Boolean] true - because we want a consistant response for this method
|
53
|
+
# @api private
|
54
|
+
def set_response!
|
55
|
+
get_responding_methods
|
56
|
+
begin
|
57
|
+
self.responding_object = @responding_object
|
58
|
+
if successful?
|
59
|
+
self.status_message = @success_message || "Status: successful"
|
60
|
+
else
|
61
|
+
self.status_message = @failure_message || "Status: unsuccessful"
|
62
|
+
end
|
63
|
+
rescue Exception => e
|
64
|
+
self.responding_object = e.class
|
65
|
+
self.status_message = e.message
|
66
|
+
end
|
67
|
+
return true
|
68
|
+
end
|
69
|
+
|
70
|
+
# Gets the responding methods
|
71
|
+
#
|
72
|
+
# @example
|
73
|
+
# response.get_responding_methods
|
74
|
+
# @return [Hash] a hash methods as keys and their return as values
|
75
|
+
# @api private
|
76
|
+
def get_responding_methods
|
77
|
+
meth_responses = {}
|
78
|
+
@responding_methods.each do |meth|
|
79
|
+
begin
|
80
|
+
if meth.is_a? Hash
|
81
|
+
meth.each_pair { |k,v|
|
82
|
+
meth_responses[k.to_sym] = @responding_object.send(k, *v)
|
83
|
+
}
|
84
|
+
else
|
85
|
+
meth_responses[meth.to_sym] = @responding_object.send(meth)
|
86
|
+
end
|
87
|
+
rescue Exception => e
|
88
|
+
if meth.is_a? Hash
|
89
|
+
meth.each_pair { |k,v|
|
90
|
+
meth_responses[k.to_sym] = "#{e.class}: #{e.message}"
|
91
|
+
}
|
92
|
+
else
|
93
|
+
meth_responses[meth.to_sym] = "#{e.class}: #{e.message}"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
self.responding_methods = meth_responses
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
File without changes
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Set up simplecov
|
2
|
+
require 'simplecov'
|
3
|
+
require 'simplecov-rcov'
|
4
|
+
SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
|
5
|
+
SimpleCov.start 'rails'
|
6
|
+
|
7
|
+
# Setup turn
|
8
|
+
require 'turn/autorun'
|
9
|
+
require 'ansi'
|
10
|
+
Turn.config do |conf|
|
11
|
+
conf.format = :outline
|
12
|
+
conf.verbose = true
|
13
|
+
conf.trace = nil
|
14
|
+
conf.natural = true
|
15
|
+
conf.ansi = true
|
16
|
+
end
|
17
|
+
|
18
|
+
require 'mocha/setup'
|
19
|
+
require 'ostruct'
|
20
|
+
require 'pry'
|
21
|
+
|
22
|
+
# Load support files
|
23
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
24
|
+
|
25
|
+
# Load the app
|
26
|
+
require File.expand_path("../../lib/holla_back.rb", __FILE__)
|
27
|
+
|
28
|
+
# A test class for our specs
|
29
|
+
class TestClass
|
30
|
+
include HollaBack
|
31
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe HollaBack::OptionLoader do
|
4
|
+
subject { HollaBack::OptionLoader }
|
5
|
+
|
6
|
+
it 'should load an option into an instance variable' do
|
7
|
+
subject.load_option(:foo, {:foo => 'bar'})
|
8
|
+
subject.instance_variable_defined?('@foo').must_equal true
|
9
|
+
subject.instance_variable_get('@foo').must_equal 'bar'
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should load multiple options into many instance variables' do
|
13
|
+
n = 0
|
14
|
+
subject.load_options({:foo1 => 'bar1', :foo2 => 'bar2'}, :foo1, :foo2)
|
15
|
+
[:foo1, :foo2].each do |v|
|
16
|
+
n += 1
|
17
|
+
subject.instance_variable_defined?("@#{v.to_s}").must_equal true
|
18
|
+
subject.instance_variable_get("@#{v.to_s}").must_equal "bar#{n}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe HollaBack::Response do
|
4
|
+
describe "A successful response" do
|
5
|
+
before do
|
6
|
+
responding_object = mock('responding_object')
|
7
|
+
responding_object.expects(:status_meth).returns(true).at_least_once
|
8
|
+
responding_object.expects(:meth1).returns(42).at_least_once
|
9
|
+
responding_object.expects(:meth2).with('param').returns(42).at_least_once
|
10
|
+
responding_methods = [:meth1, {:meth2 => ['param']}]
|
11
|
+
@options = {
|
12
|
+
responding_methods: responding_methods,
|
13
|
+
status_method: 'status_meth',
|
14
|
+
success_message: 'success',
|
15
|
+
failure_message: 'failure'
|
16
|
+
}
|
17
|
+
@response = HollaBack::Response.new(responding_object, @options)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should provide a successful status method' do
|
21
|
+
@response.successful?.must_equal true
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should provide the responding methods' do
|
25
|
+
@response.responding_methods.must_be_kind_of Hash
|
26
|
+
@response.responding_methods[:meth1].must_equal 42
|
27
|
+
@response.responding_methods[:meth2].must_equal 42
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should return the success message' do
|
31
|
+
@response.status_message.must_be_kind_of String
|
32
|
+
@response.status_message.must_equal "success"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "A unsuccessful response" do
|
37
|
+
before do
|
38
|
+
responding_object = mock('responding_object')
|
39
|
+
responding_object.expects(:status_meth).returns([false, nil].sample).at_least_once
|
40
|
+
responding_object.expects(:meth).returns(42).at_least_once
|
41
|
+
responding_methods = ['meth']
|
42
|
+
@options = {
|
43
|
+
responding_methods: responding_methods,
|
44
|
+
status_method: 'status_meth',
|
45
|
+
success_message: 'success',
|
46
|
+
failure_message: 'failure'
|
47
|
+
}
|
48
|
+
@response = HollaBack::Response.new(responding_object, @options)
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should provide a successful status method' do
|
52
|
+
@response.successful?.must_equal false
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should provide the responding methods' do
|
56
|
+
@response.responding_methods.must_be_kind_of Hash
|
57
|
+
@response.responding_methods[:meth].must_equal 42
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'should return the success message' do
|
61
|
+
@response.status_message.must_be_kind_of String
|
62
|
+
@response.status_message.must_equal "failure"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "A unsuccessful response due to a undefined methods" do
|
67
|
+
before do
|
68
|
+
responding_object = TestClass.new
|
69
|
+
responding_methods = ['meth', 'class', {:thing_that_doesnt_exist => ['test']}]
|
70
|
+
@options = {
|
71
|
+
responding_object: responding_object,
|
72
|
+
responding_methods: responding_methods,
|
73
|
+
status_method: 'unkown_status_meth',
|
74
|
+
success_message: 'success',
|
75
|
+
failure_message: 'failure'
|
76
|
+
}
|
77
|
+
@response = HollaBack::Response.new(responding_object, @options)
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'should return the exception class as the responding object' do
|
81
|
+
@response.responding_object.must_equal NoMethodError
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'should provide the error message as the response' do
|
85
|
+
@response.status_message.must_be_kind_of String
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe HollaBack do
|
4
|
+
subject { HollaBack }
|
5
|
+
|
6
|
+
before do
|
7
|
+
@test_class = TestClass.new
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should be included into a class' do
|
11
|
+
@test_class.class.included_modules.must_include subject
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should inject a response method' do
|
15
|
+
@test_class.must_respond_to :response
|
16
|
+
end
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,320 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: holla_back
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Chapman
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-06-27 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.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest-matchers
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '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'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest-reporters
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rake
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: simplecov
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: simplecov-rcov
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: yard
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - '>='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - '>='
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: yardstick
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - '>='
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - '>='
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: redcarpet
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - '>='
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - '>='
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: guard-minitest
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - '>='
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
type: :development
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - '>='
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0'
|
195
|
+
- !ruby/object:Gem::Dependency
|
196
|
+
name: libnotify
|
197
|
+
requirement: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - '>='
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: '0'
|
202
|
+
type: :development
|
203
|
+
prerelease: false
|
204
|
+
version_requirements: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - '>='
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: '0'
|
209
|
+
- !ruby/object:Gem::Dependency
|
210
|
+
name: mocha
|
211
|
+
requirement: !ruby/object:Gem::Requirement
|
212
|
+
requirements:
|
213
|
+
- - '>='
|
214
|
+
- !ruby/object:Gem::Version
|
215
|
+
version: '0'
|
216
|
+
type: :development
|
217
|
+
prerelease: false
|
218
|
+
version_requirements: !ruby/object:Gem::Requirement
|
219
|
+
requirements:
|
220
|
+
- - '>='
|
221
|
+
- !ruby/object:Gem::Version
|
222
|
+
version: '0'
|
223
|
+
- !ruby/object:Gem::Dependency
|
224
|
+
name: version
|
225
|
+
requirement: !ruby/object:Gem::Requirement
|
226
|
+
requirements:
|
227
|
+
- - '>='
|
228
|
+
- !ruby/object:Gem::Version
|
229
|
+
version: '0'
|
230
|
+
type: :development
|
231
|
+
prerelease: false
|
232
|
+
version_requirements: !ruby/object:Gem::Requirement
|
233
|
+
requirements:
|
234
|
+
- - '>='
|
235
|
+
- !ruby/object:Gem::Version
|
236
|
+
version: '0'
|
237
|
+
- !ruby/object:Gem::Dependency
|
238
|
+
name: turn
|
239
|
+
requirement: !ruby/object:Gem::Requirement
|
240
|
+
requirements:
|
241
|
+
- - '>='
|
242
|
+
- !ruby/object:Gem::Version
|
243
|
+
version: '0'
|
244
|
+
type: :development
|
245
|
+
prerelease: false
|
246
|
+
version_requirements: !ruby/object:Gem::Requirement
|
247
|
+
requirements:
|
248
|
+
- - '>='
|
249
|
+
- !ruby/object:Gem::Version
|
250
|
+
version: '0'
|
251
|
+
- !ruby/object:Gem::Dependency
|
252
|
+
name: ansi
|
253
|
+
requirement: !ruby/object:Gem::Requirement
|
254
|
+
requirements:
|
255
|
+
- - '>='
|
256
|
+
- !ruby/object:Gem::Version
|
257
|
+
version: '0'
|
258
|
+
type: :development
|
259
|
+
prerelease: false
|
260
|
+
version_requirements: !ruby/object:Gem::Requirement
|
261
|
+
requirements:
|
262
|
+
- - '>='
|
263
|
+
- !ruby/object:Gem::Version
|
264
|
+
version: '0'
|
265
|
+
description: A simple Ruby gem for providing a response standard to your libraries
|
266
|
+
email:
|
267
|
+
- david@isotope11.com
|
268
|
+
executables: []
|
269
|
+
extensions: []
|
270
|
+
extra_rdoc_files: []
|
271
|
+
files:
|
272
|
+
- .gitignore
|
273
|
+
- .rvmrc
|
274
|
+
- Gemfile
|
275
|
+
- Guardfile
|
276
|
+
- LICENSE.txt
|
277
|
+
- README.md
|
278
|
+
- Rakefile
|
279
|
+
- VERSION
|
280
|
+
- holla_back.gemspec
|
281
|
+
- lib/holla_back.rb
|
282
|
+
- lib/holla_back/option_loader.rb
|
283
|
+
- lib/holla_back/response.rb
|
284
|
+
- test/support/.gitkeep
|
285
|
+
- test/test_helper.rb
|
286
|
+
- test/unit/holla_back/option_loader_test.rb
|
287
|
+
- test/unit/holla_back/response_test.rb
|
288
|
+
- test/unit/holla_back_test.rb
|
289
|
+
homepage: ''
|
290
|
+
licenses:
|
291
|
+
- MIT
|
292
|
+
metadata: {}
|
293
|
+
post_install_message:
|
294
|
+
rdoc_options: []
|
295
|
+
require_paths:
|
296
|
+
- lib
|
297
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
298
|
+
requirements:
|
299
|
+
- - '>='
|
300
|
+
- !ruby/object:Gem::Version
|
301
|
+
version: '0'
|
302
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
303
|
+
requirements:
|
304
|
+
- - '>='
|
305
|
+
- !ruby/object:Gem::Version
|
306
|
+
version: '0'
|
307
|
+
requirements: []
|
308
|
+
rubyforge_project:
|
309
|
+
rubygems_version: 2.0.3
|
310
|
+
signing_key:
|
311
|
+
specification_version: 4
|
312
|
+
summary: HollaBack will simply provide a unified response object containing needed
|
313
|
+
information and responses.
|
314
|
+
test_files:
|
315
|
+
- test/support/.gitkeep
|
316
|
+
- test/test_helper.rb
|
317
|
+
- test/unit/holla_back/option_loader_test.rb
|
318
|
+
- test/unit/holla_back/response_test.rb
|
319
|
+
- test/unit/holla_back_test.rb
|
320
|
+
has_rdoc:
|