pure_promise 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 +15 -0
- data/.rspec +3 -0
- data/.travis.yml +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +172 -0
- data/Rakefile +6 -0
- data/lib/pure_promise.rb +135 -0
- data/lib/pure_promise/callback.rb +19 -0
- data/lib/pure_promise/coercer.rb +59 -0
- data/pure_promise.gemspec +23 -0
- data/spec/pure_promise/callback_spec.rb +26 -0
- data/spec/pure_promise/coercer_spec.rb +118 -0
- data/spec/pure_promise_spec.rb +445 -0
- data/spec/spec_helper.rb +67 -0
- data/spec/support/helper_macros.rb +37 -0
- data/spec/support/matchers.rb +47 -0
- data/spec/support/thenable.rb +44 -0
- metadata +113 -0
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'pure_promise'
|
2
|
+
|
3
|
+
SPEC_ROOT = File.dirname(__FILE__)
|
4
|
+
|
5
|
+
Dir[File.join(SPEC_ROOT, 'support/**/*.rb')].each { |f| require f }
|
6
|
+
|
7
|
+
RSpec.configure do |config|
|
8
|
+
|
9
|
+
# These two settings work together to allow you to limit a spec run
|
10
|
+
# to individual examples or groups you care about by tagging them with
|
11
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
12
|
+
# get run.
|
13
|
+
#config.filter_run :focus
|
14
|
+
config.run_all_when_everything_filtered = true
|
15
|
+
|
16
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
17
|
+
# file, and it's useful to allow more verbose output when running an
|
18
|
+
# individual spec file.
|
19
|
+
if config.files_to_run.one?
|
20
|
+
# Use the documentation formatter for detailed output,
|
21
|
+
# unless a formatter has already been configured
|
22
|
+
# (e.g. via a command-line flag).
|
23
|
+
config.default_formatter = 'doc'
|
24
|
+
end
|
25
|
+
|
26
|
+
# Print the 10 slowest examples and example groups at the
|
27
|
+
# end of the spec run, to help surface which specs are running
|
28
|
+
# particularly slow.
|
29
|
+
config.profile_examples = 10
|
30
|
+
|
31
|
+
# Run specs in random order to surface order dependencies. If you find an
|
32
|
+
# order dependency and want to debug it, you can fix the order by providing
|
33
|
+
# the seed, which is printed after each run.
|
34
|
+
# --seed 1234
|
35
|
+
config.order = :random
|
36
|
+
|
37
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
38
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
39
|
+
# test failures related to randomization by passing the same `--seed` value
|
40
|
+
# as the one that triggered the failure.
|
41
|
+
Kernel.srand config.seed
|
42
|
+
|
43
|
+
# rspec-expectations config goes here. You can use an alternate
|
44
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
45
|
+
# assertions if you prefer.
|
46
|
+
config.expect_with :rspec do |expectations|
|
47
|
+
# Enable only the newer, non-monkey-patching expect syntax.
|
48
|
+
# For more details, see:
|
49
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
50
|
+
expectations.syntax = :expect
|
51
|
+
end
|
52
|
+
|
53
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
54
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
55
|
+
config.mock_with :rspec do |mocks|
|
56
|
+
# Enable only the newer, non-monkey-patching expect syntax.
|
57
|
+
# For more details, see:
|
58
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
59
|
+
mocks.syntax = :expect
|
60
|
+
|
61
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
62
|
+
# a real object. This is generally recommended.
|
63
|
+
mocks.verify_partial_doubles = true
|
64
|
+
end
|
65
|
+
|
66
|
+
config.include HelperMacros
|
67
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module HelperMacros
|
2
|
+
def expect_fulfillment(promise, options={})
|
3
|
+
setup_state_expectation(promise) do |fulfill_callback, reject_callback|
|
4
|
+
yield if block_given?
|
5
|
+
|
6
|
+
expect(fulfill_callback).to have_received(:call).with(options[:with] || anything)
|
7
|
+
expect(reject_callback).to_not have_received(:call)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def expect_rejection(promise, options={})
|
12
|
+
setup_state_expectation(promise) do |fulfill_callback, reject_callback|
|
13
|
+
yield if block_given?
|
14
|
+
|
15
|
+
expect(reject_callback).to have_received(:call).with(options[:with] || anything)
|
16
|
+
expect(fulfill_callback).to_not have_received(:call)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def expect_pending(promise)
|
21
|
+
setup_state_expectation(promise) do |fulfill_callback, reject_callback|
|
22
|
+
expect(fulfill_callback).to_not have_received(:call)
|
23
|
+
expect(reject_callback).to_not have_received(:call)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def setup_state_expectation(promise)
|
30
|
+
fulfill_callback = double('fulfill_callback', call: PurePromise.fulfill)
|
31
|
+
reject_callback = double('reject_callback', call: PurePromise.reject)
|
32
|
+
|
33
|
+
promise.then(fulfill_callback, reject_callback)
|
34
|
+
|
35
|
+
yield fulfill_callback, reject_callback
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
RSpec::Matchers.define :be_a_bound_method_of do |unbound_method|
|
2
|
+
match do |bound_method|
|
3
|
+
bound_method.unbind == unbound_method
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
RSpec::Matchers.alias_matcher :a_bound_method_of, :be_a_bound_method_of
|
8
|
+
|
9
|
+
class Exception
|
10
|
+
def inspect
|
11
|
+
[
|
12
|
+
'an error',
|
13
|
+
"class: #{self.class.inspect}",
|
14
|
+
"message: #{message.inspect}",
|
15
|
+
"backtrace: #{backtrace.inspect}"
|
16
|
+
].join(', ')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
RSpec::Matchers.define :be_an_error do |error_class=nil, message=nil|
|
21
|
+
match do |error|
|
22
|
+
[
|
23
|
+
error.is_a?(error_class || RuntimeError),
|
24
|
+
@backtrace.nil? || (error.backtrace == @backtrace),
|
25
|
+
message.nil? || (error.message == message)
|
26
|
+
].all?
|
27
|
+
end
|
28
|
+
|
29
|
+
chain :with_backtrace do |backtrace|
|
30
|
+
@backtrace = backtrace
|
31
|
+
end
|
32
|
+
|
33
|
+
description do
|
34
|
+
[
|
35
|
+
'an error',
|
36
|
+
("class: #{error_class.inspect}" if error_class),
|
37
|
+
("message: #{message.inspect}" if message),
|
38
|
+
("backtrace: #{@backtrace.inspect}" if @backtrace)
|
39
|
+
].compact.join(', ')
|
40
|
+
end
|
41
|
+
|
42
|
+
#failure_message do |error|
|
43
|
+
# "expected error to have backtrace #{expected_backtrace.inspect}, actually got #{error.backtrace.inspect}"
|
44
|
+
#end
|
45
|
+
end
|
46
|
+
|
47
|
+
RSpec::Matchers.alias_matcher :an_error, :be_an_error
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Thenable
|
2
|
+
class Conformant
|
3
|
+
|
4
|
+
def fulfill(value)
|
5
|
+
@fulfill_callback.call(value)
|
6
|
+
end
|
7
|
+
|
8
|
+
def reject(value)
|
9
|
+
@reject_callback.call(value)
|
10
|
+
end
|
11
|
+
|
12
|
+
def then(fulfill_callback, reject_callback)
|
13
|
+
@fulfill_callback = fulfill_callback
|
14
|
+
@reject_callback = reject_callback
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
class EarlyErroring
|
20
|
+
|
21
|
+
def initialize(error)
|
22
|
+
@error = error
|
23
|
+
end
|
24
|
+
|
25
|
+
def then(_, _)
|
26
|
+
raise @error
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
class LateErroring
|
32
|
+
|
33
|
+
def initialize(value, error)
|
34
|
+
@value = value
|
35
|
+
@error = error
|
36
|
+
end
|
37
|
+
|
38
|
+
def then(fulfill_callback, _)
|
39
|
+
fulfill_callback.call(@value)
|
40
|
+
raise @error
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pure_promise
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Cameron Martin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-17 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.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
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.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.0'
|
55
|
+
description: Promises/A+ with a twist. Resolves some of the inconsistencies and annoyances
|
56
|
+
I've experienced with other promises libraries
|
57
|
+
email:
|
58
|
+
- cameronmartin123@gmail.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".rspec"
|
65
|
+
- ".travis.yml"
|
66
|
+
- Gemfile
|
67
|
+
- LICENSE.txt
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- lib/pure_promise.rb
|
71
|
+
- lib/pure_promise/callback.rb
|
72
|
+
- lib/pure_promise/coercer.rb
|
73
|
+
- pure_promise.gemspec
|
74
|
+
- spec/pure_promise/callback_spec.rb
|
75
|
+
- spec/pure_promise/coercer_spec.rb
|
76
|
+
- spec/pure_promise_spec.rb
|
77
|
+
- spec/spec_helper.rb
|
78
|
+
- spec/support/helper_macros.rb
|
79
|
+
- spec/support/matchers.rb
|
80
|
+
- spec/support/thenable.rb
|
81
|
+
homepage: ''
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
metadata: {}
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 2.2.2
|
102
|
+
signing_key:
|
103
|
+
specification_version: 4
|
104
|
+
summary: Promises/A+ with a twist
|
105
|
+
test_files:
|
106
|
+
- spec/pure_promise/callback_spec.rb
|
107
|
+
- spec/pure_promise/coercer_spec.rb
|
108
|
+
- spec/pure_promise_spec.rb
|
109
|
+
- spec/spec_helper.rb
|
110
|
+
- spec/support/helper_macros.rb
|
111
|
+
- spec/support/matchers.rb
|
112
|
+
- spec/support/thenable.rb
|
113
|
+
has_rdoc:
|