less_interactions 0.0.11
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/.document +5 -0
- data/Gemfile +23 -0
- data/Gemfile.lock +44 -0
- data/Guardfile +8 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +117 -0
- data/Rakefile +46 -0
- data/VERSION +1 -0
- data/less_interactions.gemspec +64 -0
- data/lib/less_interactions.rb +2 -0
- data/lib/less_interactions/interaction.rb +95 -0
- data/lib/less_interactions/response.rb +26 -0
- data/test/interaction_test.rb +153 -0
- data/test/test_helper.rb +19 -0
- metadata +159 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: dba43aa68a826eeb48e8f3dc6dee8a8fcdbf793a
|
4
|
+
data.tar.gz: b6f91f9696b8b2fa184f31340e02ca915306bee6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9a556146945d4b2dd4354f40d016543ff595ec828a1b44f47c18b7ba5bb896bbfabe160be329031986d8a306c164af2d353fa5e24ffe3ac22798c0e6d42723a8
|
7
|
+
data.tar.gz: 0a53215447e698f233587bd8b0bfd5550a86dd19a9368858028924b268eec15ae7d7feaedc3e7aab9f5ad2b692061fcdbd039bf3653c4fc2cea38398444318a1
|
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "yard", "~> 0.7"
|
10
|
+
gem "rdoc", "~> 3.12"
|
11
|
+
gem "bundler", "~> 1.0.0"
|
12
|
+
gem "jeweler", "~> 1.8.3"
|
13
|
+
#gem "rcov", ">= 0"
|
14
|
+
|
15
|
+
gem "guard", ">= 0"
|
16
|
+
gem "guard-test", ">= 0"
|
17
|
+
end
|
18
|
+
|
19
|
+
group :test do
|
20
|
+
gem "shoulda", ">= 0"
|
21
|
+
gem "mocha", ">= 0"
|
22
|
+
gem "mocha", ">= 0"
|
23
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
ffi (1.0.11)
|
5
|
+
git (1.2.5)
|
6
|
+
guard (1.0.1)
|
7
|
+
ffi (>= 0.5.0)
|
8
|
+
thor (~> 0.14.6)
|
9
|
+
guard-test (0.4.3)
|
10
|
+
guard (>= 0.4)
|
11
|
+
test-unit (~> 2.2)
|
12
|
+
jeweler (1.8.3)
|
13
|
+
bundler (~> 1.0)
|
14
|
+
git (>= 1.2.5)
|
15
|
+
rake
|
16
|
+
rdoc
|
17
|
+
json (1.6.5)
|
18
|
+
metaclass (0.0.1)
|
19
|
+
mocha (0.10.5)
|
20
|
+
metaclass (~> 0.0.1)
|
21
|
+
rake (0.9.2.2)
|
22
|
+
rdoc (3.12)
|
23
|
+
json (~> 1.4)
|
24
|
+
shoulda (3.0.1)
|
25
|
+
shoulda-context (~> 1.0.0)
|
26
|
+
shoulda-matchers (~> 1.0.0)
|
27
|
+
shoulda-context (1.0.0)
|
28
|
+
shoulda-matchers (1.0.0)
|
29
|
+
test-unit (2.4.8)
|
30
|
+
thor (0.14.6)
|
31
|
+
yard (0.7.5)
|
32
|
+
|
33
|
+
PLATFORMS
|
34
|
+
ruby
|
35
|
+
|
36
|
+
DEPENDENCIES
|
37
|
+
bundler (~> 1.0.0)
|
38
|
+
guard
|
39
|
+
guard-test
|
40
|
+
jeweler (~> 1.8.3)
|
41
|
+
mocha
|
42
|
+
rdoc (~> 3.12)
|
43
|
+
shoulda
|
44
|
+
yard (~> 0.7)
|
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Eugen Minciu
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
= less_interactions
|
2
|
+
|
3
|
+
A new way to think about your Ruby applications.
|
4
|
+
|
5
|
+
== What is it?
|
6
|
+
|
7
|
+
Less::Interactions are a place to put all of your business logic. They're intended to be used primarily inside a rails app but they don't need rails to work.
|
8
|
+
|
9
|
+
== What problem is it solving?
|
10
|
+
|
11
|
+
Rails is great, but if you build a rails app of any size you start running into problems:
|
12
|
+
* ActiveRecord's before & after filters are the devil.
|
13
|
+
* The code paths in my rails app are a fucking mess.
|
14
|
+
* Where do I put this bit of code?
|
15
|
+
* Having a model call another model just to call the previous model is stupid and error prone.
|
16
|
+
* Where is the entry point to my app? Sometimes you access the app from places other than the controller (cron, console, background jobs), how do you know a safe entry point.
|
17
|
+
* What are all the side effects of calling this method?
|
18
|
+
|
19
|
+
|
20
|
+
== Dear jesus and baby jesus, what do I do?!
|
21
|
+
|
22
|
+
Less::Interactions are a place to put all of your business logic and still get all the rails goodness you love.
|
23
|
+
|
24
|
+
== Example
|
25
|
+
|
26
|
+
|
27
|
+
Before:
|
28
|
+
|
29
|
+
class ExpensesController < ApplicationController
|
30
|
+
|
31
|
+
def create
|
32
|
+
@expense = current_business.expenses.create params[:expense]
|
33
|
+
respond_with @expense
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
class Expense < ActiveRecord::Base
|
40
|
+
|
41
|
+
# all sorts of before and after filters
|
42
|
+
# doing things like updating bank account balances, budgets
|
43
|
+
# creating other models like ExpenseItem or Transaction
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
After:
|
49
|
+
|
50
|
+
# You don't need a context class, but we really like using one.
|
51
|
+
class Context
|
52
|
+
|
53
|
+
def initialize *args
|
54
|
+
args[0].each do |name, value|
|
55
|
+
instance_variable_set "@#{name}", value
|
56
|
+
eval "def #{name}; instance_variable_get :@#{name}; end"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
#Controller is basically the same
|
63
|
+
class ExpensesController < ApplicationController
|
64
|
+
|
65
|
+
def create
|
66
|
+
@expense = Expenses::Save.run Context.new( business:current_business, user: current_user, params: params), some_other_thing_the_interaction_needs: "boo"
|
67
|
+
respond_with @expense
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
# found in /app/interactions/expenses.save.rb
|
73
|
+
class Expenses::Save < Less::Interaction
|
74
|
+
|
75
|
+
# A simple way of both enforcing params get passed in and creates and i_var and a getter for each expects
|
76
|
+
# set an expectation for all the objects the context provides
|
77
|
+
expects :some_other_thing_the_interaction_needs, allow_nil: true
|
78
|
+
expects :business
|
79
|
+
expects :user
|
80
|
+
|
81
|
+
# method chain in use case is easy to see.
|
82
|
+
def run
|
83
|
+
do_somthing_with some_other_thing_the_interaction_needs
|
84
|
+
build_or_find_an_expense
|
85
|
+
setup_expense_items
|
86
|
+
setup_transaction
|
87
|
+
return @expense unless valid?
|
88
|
+
save
|
89
|
+
update_budgets
|
90
|
+
update_bank_accounts
|
91
|
+
@expense
|
92
|
+
end
|
93
|
+
|
94
|
+
private
|
95
|
+
|
96
|
+
# implementation of other methods
|
97
|
+
# some of which call other interactions
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
== Contributing to less_interactions
|
106
|
+
|
107
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
108
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
109
|
+
* Fork the project.
|
110
|
+
* Start a feature/bugfix branch.
|
111
|
+
* Commit and push until you are happy with your contribution.
|
112
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
113
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
114
|
+
|
115
|
+
== Copyright
|
116
|
+
|
117
|
+
Copyright (c) 2015 LessEverything See LICENSE.txt for further details.
|
data/Rakefile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "less_interactions"
|
18
|
+
gem.homepage = "http://github.com/LessEverything/less_interactions"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{A new way to think about Ruby applications.}
|
21
|
+
gem.description = %Q{A new way to think about Ruby applications.}
|
22
|
+
gem.email = "eugen@lesseverything.com"
|
23
|
+
gem.authors = ["Eugen Minciu", "Dejan Simic", "Steven Bristol"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
test.pattern = 'test/**/*_test.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
|
35
|
+
# require 'rcov/rcovtask'
|
36
|
+
# Rcov::RcovTask.new do |test|
|
37
|
+
# test.libs << 'test'
|
38
|
+
# test.pattern = 'test/**/*_test.rb'
|
39
|
+
# test.verbose = true
|
40
|
+
# test.rcov_opts << '--exclude "gems/*"'
|
41
|
+
# end
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'yard'
|
46
|
+
YARD::Rake::YardocTask.new
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.8
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{less_interactions}
|
8
|
+
s.version = "0.0.11"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Eugen Minciu", "Steven Bristol"]
|
12
|
+
s.date = %q{2012-03-24}
|
13
|
+
s.description = %q{A new way to think about Ruby applications.}
|
14
|
+
s.email = %q{eugen@lesseverything.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
"Gemfile",
|
22
|
+
"Gemfile.lock",
|
23
|
+
"Guardfile",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"less_interactions.gemspec",
|
29
|
+
"lib/less_interactions.rb",
|
30
|
+
"lib/less_interactions/interaction.rb",
|
31
|
+
"lib/less_interactions/response.rb",
|
32
|
+
"test/interaction_test.rb",
|
33
|
+
"test/test_helper.rb"
|
34
|
+
]
|
35
|
+
s.homepage = %q{http://github.com/LessEverything/less_interactions}
|
36
|
+
s.licenses = ["MIT"]
|
37
|
+
s.require_paths = ["lib"]
|
38
|
+
s.rubygems_version = %q{1.4.2}
|
39
|
+
s.summary = %q{A new way to think about Ruby applications.}
|
40
|
+
|
41
|
+
if s.respond_to? :specification_version then
|
42
|
+
s.specification_version = 3
|
43
|
+
|
44
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
45
|
+
s.add_development_dependency(%q<yard>, ["~> 0.7"])
|
46
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
47
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
48
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
|
49
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
50
|
+
s.add_development_dependency(%q<guard>, [">= 0"])
|
51
|
+
s.add_development_dependency(%q<guard-test>, [">= 0"])
|
52
|
+
else
|
53
|
+
s.add_dependency(%q<yard>, ["~> 0.7"])
|
54
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
55
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
56
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
57
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
58
|
+
s.add_dependency(%q<guard>, [">= 0"])
|
59
|
+
s.add_dependency(%q<guard-test>, [">= 0"])
|
60
|
+
end
|
61
|
+
else
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
@@ -0,0 +1,95 @@
|
|
1
|
+
|
2
|
+
module Less
|
3
|
+
class Interaction
|
4
|
+
# Initialize the objects for an interaction.
|
5
|
+
# @param [Object] context The context for running an interaction. Optional param.
|
6
|
+
# @param [Hash] options The options are passed when running an interaction. Optional param.
|
7
|
+
def initialize(context = {}, options = {})
|
8
|
+
#the param context = {} is to allow for interactions with no context
|
9
|
+
if context.is_a? Hash
|
10
|
+
options.merge! context #context is not a Context so merge it in
|
11
|
+
else
|
12
|
+
options[:context] = context # add context to the options so will get the ivar and getter
|
13
|
+
end
|
14
|
+
|
15
|
+
ex = self.class.expectations.dup
|
16
|
+
n = ex.keep_if {|name, allow_nil| allow_nil.has_key?(:allow_nil) && allow_nil[:allow_nil]}
|
17
|
+
nils = {}
|
18
|
+
n.each do |name, val|
|
19
|
+
nils[name] = nil
|
20
|
+
end
|
21
|
+
nils.merge(options).each do |name, value|
|
22
|
+
instance_variable_set "@#{name}", value
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
attr_reader :context
|
27
|
+
|
28
|
+
# Definition of the interaction itself. You should override this in your interactions
|
29
|
+
#
|
30
|
+
# The default implementation raises an {InvalidInteractionError}
|
31
|
+
def run
|
32
|
+
raise InvalidInteractionError, "You most override the run instance method in #{self.class}"
|
33
|
+
end
|
34
|
+
|
35
|
+
def init
|
36
|
+
end
|
37
|
+
|
38
|
+
# Run your interaction.
|
39
|
+
# @param [Object] context
|
40
|
+
# @param [Hash] options
|
41
|
+
#
|
42
|
+
# This will initialize your interaction with the options you pass to it and then call its {#run} method.
|
43
|
+
def self.run(context = {}, options = {})
|
44
|
+
me = new(context, options)
|
45
|
+
me.init
|
46
|
+
raise MissingParameterError unless me.send :expectations_met?
|
47
|
+
me.run
|
48
|
+
end
|
49
|
+
|
50
|
+
# Expect certain parameters to be present. If any parameter can't be found, a {MissingParameterError} will be raised.
|
51
|
+
# @overload expects(*parameters)
|
52
|
+
# @param *parameters A list of parameters that your interaction expects to find.
|
53
|
+
# @overload expects(*parameters, options)
|
54
|
+
# @param *parameters A list of parameters that your interaction expects to find.
|
55
|
+
# @param options A list of options for the exclusion
|
56
|
+
# @option options :allow_nil Allow nil values to be passed to the interaction, only check to see whether the key has been set
|
57
|
+
|
58
|
+
def self.expects(*parameters)
|
59
|
+
if parameters.last.is_a?(Hash)
|
60
|
+
options = parameters.pop
|
61
|
+
else
|
62
|
+
options = {}
|
63
|
+
end
|
64
|
+
parameters.each do |param|
|
65
|
+
methods = (self.instance_methods + self.private_instance_methods)
|
66
|
+
self.send(:attr_reader, param.to_sym) unless methods.member?(param.to_sym)
|
67
|
+
add_expectation(param, options)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def self.add_expectation(parameter, options)
|
76
|
+
expectations[parameter] = options
|
77
|
+
end
|
78
|
+
|
79
|
+
def expectations_met?
|
80
|
+
self.class.expectations.each do |param, param_options|
|
81
|
+
unless param_options[:allow_nil]
|
82
|
+
raise MissingParameterError, "Parameter empty :#{param.to_s}" if instance_variable_get("@#{param}").nil?
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def self.expectations
|
88
|
+
@expectations ||= {}
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
class InvalidInteractionError < StandardError; end
|
94
|
+
class MissingParameterError < StandardError; end
|
95
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class Less::Response
|
2
|
+
|
3
|
+
attr_accessor :status, :object
|
4
|
+
def initialize(status, object)
|
5
|
+
@status = status
|
6
|
+
@object = object
|
7
|
+
end
|
8
|
+
|
9
|
+
def success?
|
10
|
+
(200..299).cover? status
|
11
|
+
end
|
12
|
+
|
13
|
+
def error?
|
14
|
+
!success?
|
15
|
+
end
|
16
|
+
|
17
|
+
def client_error?
|
18
|
+
(400..499).cover? status
|
19
|
+
end
|
20
|
+
|
21
|
+
def server_error?
|
22
|
+
(500..599).cover? status
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,153 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
class InteractionTest < Test::Unit::TestCase
|
3
|
+
include Less
|
4
|
+
|
5
|
+
should "not be able to run an interaction without run defined" do
|
6
|
+
class InteractionWithoutRun < Interaction; end
|
7
|
+
assert_raise(InvalidInteractionError) { InteractionWithoutRun.run }
|
8
|
+
end
|
9
|
+
|
10
|
+
should "be able to run an interaction with run defined" do
|
11
|
+
class InteractionWithRun < Interaction ; def run; end ; end
|
12
|
+
assert_nothing_raised { InteractionWithRun.run }
|
13
|
+
end
|
14
|
+
|
15
|
+
should "run an interaction with an options hash" do
|
16
|
+
class InteractionWithAHash < Interaction; def run; end; end
|
17
|
+
assert_nothing_raised { InteractionWithAHash.run(:test => 3) }
|
18
|
+
end
|
19
|
+
|
20
|
+
should "call init when running an interaction" do
|
21
|
+
class InteractionExpectingInit < Interaction; def run; end; end
|
22
|
+
InteractionExpectingInit.any_instance.expects(:init)
|
23
|
+
InteractionExpectingInit.run
|
24
|
+
end
|
25
|
+
|
26
|
+
should "call the run instance method when running an interaction" do
|
27
|
+
class InteractionExpectingRun < Interaction; end
|
28
|
+
InteractionExpectingRun.any_instance.expects(:run)
|
29
|
+
InteractionExpectingRun.run
|
30
|
+
end
|
31
|
+
|
32
|
+
should "fail if an expected parameter is not found" do
|
33
|
+
class InteractionMissingParameter < Less::Interaction
|
34
|
+
expects :title
|
35
|
+
|
36
|
+
def run; end
|
37
|
+
end
|
38
|
+
assert_raise(MissingParameterError) { InteractionMissingParameter.run }
|
39
|
+
end
|
40
|
+
|
41
|
+
should "fail if an expected parameter is nil" do
|
42
|
+
class InteractionWithNilParameter < Less::Interaction
|
43
|
+
expects :title
|
44
|
+
|
45
|
+
def run; end
|
46
|
+
end
|
47
|
+
assert_raise(MissingParameterError) { InteractionWithNilParameter.run(:title => nil) }
|
48
|
+
end
|
49
|
+
|
50
|
+
should "run if an expected parameter is found" do
|
51
|
+
class InteractionWithParameter < Less::Interaction
|
52
|
+
expects :title
|
53
|
+
|
54
|
+
def run; end
|
55
|
+
end
|
56
|
+
assert_nothing_raised { InteractionWithParameter.run(:title => "Hello, test") }
|
57
|
+
end
|
58
|
+
|
59
|
+
should "run if an expected parameter is found, even if it is false" do
|
60
|
+
class InteractionWithParameter < Less::Interaction
|
61
|
+
expects :title
|
62
|
+
|
63
|
+
def run; end
|
64
|
+
end
|
65
|
+
assert_nothing_raised { InteractionWithParameter.run(:title => false) }
|
66
|
+
end
|
67
|
+
|
68
|
+
should "run if an expected parameter is found, even if it is nil, if the option is specified" do
|
69
|
+
class InteractionWithParameter < Less::Interaction
|
70
|
+
expects :title, :allow_nil => true
|
71
|
+
|
72
|
+
def run;end
|
73
|
+
end
|
74
|
+
assert_nothing_raised { InteractionWithParameter.run(:title => nil) }
|
75
|
+
end
|
76
|
+
|
77
|
+
should "run if an expected parameter is found, even if it is nil, if the option is not specified, but is allow_nil and is called" do
|
78
|
+
class InteractionWithParameter < Less::Interaction
|
79
|
+
expects :title, :allow_nil => true
|
80
|
+
|
81
|
+
def run; title;end
|
82
|
+
end
|
83
|
+
assert_nothing_raised { InteractionWithParameter.run() }
|
84
|
+
end
|
85
|
+
|
86
|
+
should "set ivars from options on initialize" do
|
87
|
+
i = Less::Interaction.new a: 1, b:2
|
88
|
+
assert_equal 1, i.instance_variable_get(:@a)
|
89
|
+
assert_equal 2, i.instance_variable_get(:@b)
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
should "Convert first param to context on initialize" do
|
94
|
+
i = Less::Interaction.new 1, b:2
|
95
|
+
assert_equal 1, i.instance_variable_get(:@context)
|
96
|
+
assert_equal 2, i.instance_variable_get(:@b)
|
97
|
+
end
|
98
|
+
|
99
|
+
should "be able to fake out expects" do
|
100
|
+
class FakeoutExpects < Less::Interaction
|
101
|
+
expects :object
|
102
|
+
def initialize params, options
|
103
|
+
super :object => params[:object_id].to_s #or a finder or something instead of to_s
|
104
|
+
end
|
105
|
+
def run; self; end #return self just so I can test the value
|
106
|
+
end
|
107
|
+
assert_nothing_raised do
|
108
|
+
x = FakeoutExpects.run( :object_id => 1)
|
109
|
+
assert_equal "1", x.instance_variable_get(:@object)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
should "be able to override an expects" do
|
114
|
+
|
115
|
+
class OverrideExpects < Less::Interaction
|
116
|
+
expects :object, allow_nil: true
|
117
|
+
|
118
|
+
def run; self; end #return self just so I can test the value
|
119
|
+
def object; "YES!"; end
|
120
|
+
end
|
121
|
+
|
122
|
+
x = OverrideExpects.new(1, object: "no :(").run
|
123
|
+
assert_equal "YES!", x.object
|
124
|
+
end
|
125
|
+
|
126
|
+
|
127
|
+
should "get a method that returns nil from an allow_nil expects" do
|
128
|
+
|
129
|
+
class NilExpects < Less::Interaction
|
130
|
+
expects :object, allow_nil: true
|
131
|
+
def run; self; end #return self just so I can test the value
|
132
|
+
end
|
133
|
+
|
134
|
+
x = NilExpects.run
|
135
|
+
assert_equal nil, x.object
|
136
|
+
end
|
137
|
+
|
138
|
+
should "be able to override an inherited expects" do
|
139
|
+
class OverrideExpects < Less::Interaction
|
140
|
+
expects :int
|
141
|
+
|
142
|
+
def run; self; end #return self just so I can test the value
|
143
|
+
private
|
144
|
+
def int; @int.to_s; end
|
145
|
+
end
|
146
|
+
class OverrideIt < OverrideExpects
|
147
|
+
expects :int
|
148
|
+
end
|
149
|
+
|
150
|
+
x = OverrideIt.new(int: 1).run
|
151
|
+
assert_equal "1", x.send(:int)
|
152
|
+
end
|
153
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'shoulda'
|
12
|
+
require 'mocha'
|
13
|
+
|
14
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
15
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
16
|
+
require 'less_interactions'
|
17
|
+
|
18
|
+
class Test::Unit::TestCase
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,159 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: less_interactions
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.11
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Eugen Minciu
|
8
|
+
- Steven Bristol
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-03-24 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: yard
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0.7'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0.7'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rdoc
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '3.12'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '3.12'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: bundler
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 1.0.0
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 1.0.0
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: jeweler
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 1.8.3
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.8.3
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rcov
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: guard
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: guard-test
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
description: A new way to think about Ruby applications.
|
113
|
+
email: eugen@lesseverything.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files:
|
117
|
+
- LICENSE.txt
|
118
|
+
- README.rdoc
|
119
|
+
files:
|
120
|
+
- ".document"
|
121
|
+
- Gemfile
|
122
|
+
- Gemfile.lock
|
123
|
+
- Guardfile
|
124
|
+
- LICENSE.txt
|
125
|
+
- README.rdoc
|
126
|
+
- Rakefile
|
127
|
+
- VERSION
|
128
|
+
- less_interactions.gemspec
|
129
|
+
- lib/less_interactions.rb
|
130
|
+
- lib/less_interactions/interaction.rb
|
131
|
+
- lib/less_interactions/response.rb
|
132
|
+
- test/interaction_test.rb
|
133
|
+
- test/test_helper.rb
|
134
|
+
homepage: http://github.com/LessEverything/less_interactions
|
135
|
+
licenses:
|
136
|
+
- MIT
|
137
|
+
metadata: {}
|
138
|
+
post_install_message:
|
139
|
+
rdoc_options: []
|
140
|
+
require_paths:
|
141
|
+
- lib
|
142
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
requirements: []
|
153
|
+
rubyforge_project:
|
154
|
+
rubygems_version: 2.2.2
|
155
|
+
signing_key:
|
156
|
+
specification_version: 3
|
157
|
+
summary: A new way to think about Ruby applications.
|
158
|
+
test_files: []
|
159
|
+
has_rdoc:
|