dry-transaction 0.4.0

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,99 @@
1
+ require "simplecov"
2
+ SimpleCov.minimum_coverage 100
3
+ SimpleCov.start do
4
+ add_filter "/spec/"
5
+ end
6
+
7
+ require "dry-transaction"
8
+
9
+ # Requires supporting ruby files with custom matchers and macros, etc, in
10
+ # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
11
+ # run as spec files by default. This means that files in spec/support that end
12
+ # in _spec.rb will both be required and run as specs, causing the specs to be
13
+ # run twice. It is recommended that you do not name files matching this glob to
14
+ # end with _spec.rb. You can configure this pattern with the --pattern
15
+ # option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
16
+ #
17
+ # The following line is provided for convenience purposes. It has the downside
18
+ # of increasing the boot-up time by auto-requiring all files in the support
19
+ # directory. Alternatively, in the individual `*_spec.rb` files, manually
20
+ # require only the support files necessary.
21
+ Dir[File.join(File.dirname(__FILE__), "support/**/*.rb")].each do |f| require f end
22
+
23
+ # This file was generated by the `rspec --init` command. Conventionally, all
24
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
25
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
26
+ # this file to always be loaded, without a need to explicitly require it in any
27
+ # files.
28
+ #
29
+ # Given that it is always loaded, you are encouraged to keep this file as
30
+ # light-weight as possible. Requiring heavyweight dependencies from this file
31
+ # will add to the boot time of your test suite on EVERY test run, even for an
32
+ # individual file that may not need all of that loaded. Instead, consider making
33
+ # a separate helper file that requires the additional dependencies and performs
34
+ # the additional setup, and require it from the spec files that actually need
35
+ # it.
36
+ #
37
+ # The `.rspec` file also contains a few flags that are not defaults but that
38
+ # users commonly want.
39
+ #
40
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
41
+ RSpec.configure do |config|
42
+ # rspec-expectations config goes here. You can use an alternate
43
+ # assertion/expectation library such as wrong or the stdlib/minitest
44
+ # assertions if you prefer.
45
+ config.expect_with :rspec do |expectations|
46
+ # This option will default to `true` in RSpec 4. It makes the `description`
47
+ # and `failure_message` of custom matchers include text for helper methods
48
+ # defined using `chain`, e.g.:
49
+ # be_bigger_than(2).and_smaller_than(4).description
50
+ # # => "be bigger than 2 and smaller than 4"
51
+ # ...rather than:
52
+ # # => "be bigger than 2"
53
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
54
+ end
55
+
56
+ # rspec-mocks config goes here. You can use an alternate test double
57
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
58
+ config.mock_with :rspec do |mocks|
59
+ # Prevents you from mocking or stubbing a method that does not exist on
60
+ # a real object. This is generally recommended, and will default to
61
+ # `true` in RSpec 4.
62
+ mocks.verify_partial_doubles = true
63
+ end
64
+
65
+ # Allows RSpec to persist some state between runs in order to support
66
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
67
+ # you configure your source control system to ignore this file.
68
+ config.example_status_persistence_file_path = "spec/examples.txt"
69
+
70
+ # Limits the available syntax to the non-monkey patched syntax that is
71
+ # recommended.
72
+ config.disable_monkey_patching!
73
+
74
+ # This setting enables warnings. It's recommended, but in some cases may
75
+ # be too noisy due to issues in dependencies.
76
+ config.warnings = true
77
+
78
+ # Many RSpec users commonly either run the entire suite or an individual
79
+ # file, and it's useful to allow more verbose output when running an
80
+ # individual spec file.
81
+ if config.files_to_run.one?
82
+ # Use the documentation formatter for detailed output,
83
+ # unless a formatter has already been configured
84
+ # (e.g. via a command-line flag).
85
+ config.default_formatter = "doc"
86
+ end
87
+
88
+ # Run specs in random order to surface order dependencies. If you find an
89
+ # order dependency and want to debug it, you can fix the order by providing
90
+ # the seed, which is printed after each run.
91
+ # --seed 1234
92
+ config.order = :random
93
+
94
+ # Seed global randomization in this process using the `--seed` CLI option.
95
+ # Setting this allows you to use `--seed` to deterministically reproduce
96
+ # test failures related to randomization by passing the same `--seed` value
97
+ # as the one that triggered the failure.
98
+ Kernel.srand config.seed
99
+ end
@@ -0,0 +1,11 @@
1
+ module Test
2
+ def self.remove_constants
3
+ constants.each(&method(:remove_const))
4
+ end
5
+ end
6
+
7
+ RSpec.configure do |config|
8
+ config.after do
9
+ Test.remove_constants
10
+ end
11
+ end
@@ -0,0 +1,173 @@
1
+ RSpec.describe Dry::Transaction::Sequence do
2
+ subject(:container) {
3
+ {
4
+ upcase: -> input { input.upcase },
5
+ reverse: -> input { input.reverse },
6
+ exclaim_all: -> input { input.split(" ").map { |str| str + "!" }.join(" ") },
7
+ }
8
+ }
9
+
10
+ describe "#prepend" do
11
+ let(:initial_transaction) {
12
+ Dry.Transaction(container: container) do
13
+ map :exclaim_all
14
+ end
15
+ }
16
+
17
+ it "prepends the transaction" do
18
+ other_transaction = Dry.Transaction(container: container) do
19
+ map :reverse
20
+ end
21
+ new_transaction = initial_transaction.prepend(other_transaction)
22
+
23
+ expect(new_transaction.call("hello world").right).to eq "dlrow! olleh!"
24
+ end
25
+
26
+ it "accepts a transaction defined in a block" do
27
+ new_transaction = initial_transaction.prepend(container: container) do
28
+ map :reverse
29
+ end
30
+
31
+ expect(new_transaction.call("hello world").right).to eq "dlrow! olleh!"
32
+ end
33
+
34
+ it "raises an argument error if a transaction is neither passed nor defined" do
35
+ expect { initial_transaction.prepend }.to raise_error(ArgumentError)
36
+ end
37
+
38
+ it "leaves the original transaction unmodified" do
39
+ new_transaction = initial_transaction.prepend(container: container) do
40
+ map :reverse
41
+ end
42
+
43
+ expect(initial_transaction.call("the quick brown fox").right).to eq "the! quick! brown! fox!"
44
+ end
45
+ end
46
+
47
+ describe "#append" do
48
+ let(:initial_transaction) {
49
+ Dry.Transaction(container: container) do
50
+ map :exclaim_all
51
+ end
52
+ }
53
+
54
+ it "appends the transaction" do
55
+ other_transaction = Dry.Transaction(container: container) do
56
+ map :reverse
57
+ end
58
+ new_transaction = initial_transaction.append(other_transaction)
59
+
60
+ expect(new_transaction.call("hello world").right).to eq "!dlrow !olleh"
61
+ end
62
+
63
+ it "accepts a transaction defined in a block" do
64
+ new_transaction = initial_transaction.append(container: container) do
65
+ map :reverse
66
+ end
67
+
68
+ expect(new_transaction.call("hello world").right).to eq "!dlrow !olleh"
69
+ end
70
+
71
+ it "raises an argument error if a transaction is neither passed nor defined" do
72
+ expect { initial_transaction.insert(before: :reverse) }.to raise_error(ArgumentError)
73
+ end
74
+
75
+ it "leaves the original transaction unmodified" do
76
+ new_transaction = initial_transaction.append(container: container) do
77
+ map :reverse
78
+ end
79
+
80
+ expect(initial_transaction.call("hello world").right).to eq "hello! world!"
81
+ end
82
+ end
83
+
84
+ describe "#remove" do
85
+ let(:initial_transaction) {
86
+ Dry.Transaction(container: container) do
87
+ map :upcase
88
+ map :exclaim_all
89
+ map :reverse
90
+ end
91
+ }
92
+
93
+ it "removes the specified steps" do
94
+ new_transaction = initial_transaction.remove(:exclaim_all, :reverse)
95
+ expect(new_transaction.call("hello world").right).to eq "HELLO WORLD"
96
+ end
97
+
98
+ it "leaves the original transaction unmodified" do
99
+ new_transaction = initial_transaction.remove(:exclaim_all, :reverse)
100
+ expect(initial_transaction.call("hello world").right).to eq "!DLROW !OLLEH"
101
+ end
102
+ end
103
+
104
+ describe "#insert" do
105
+ let(:initial_transaction) {
106
+ Dry.Transaction(container: container) do
107
+ map :upcase
108
+ map :reverse
109
+ end
110
+ }
111
+
112
+ it "accepts a transaction passed as an argument" do
113
+ other_transaction = Dry.Transaction(container: container) do
114
+ map :exclaim_all
115
+ end
116
+ new_transaction = initial_transaction.insert(other_transaction, before: :reverse)
117
+
118
+ expect(new_transaction.call("hello world").right).to eq "!DLROW !OLLEH"
119
+ end
120
+
121
+ it "accepts a transaction defined in a block" do
122
+ new_transaction = initial_transaction.insert(before: :reverse, container: container) do
123
+ map :exclaim_all
124
+ end
125
+
126
+ expect(new_transaction.call("hello world").right).to eq "!DLROW !OLLEH"
127
+ end
128
+
129
+ it "raises an argument error if a transaction is neither passed nor defined" do
130
+ expect { initial_transaction.insert(before: :reverse) }.to raise_error(ArgumentError)
131
+ end
132
+
133
+ it "raises an argument error if an invalid step name is provided" do
134
+ expect {
135
+ initial_transaction.insert(before: :non_existent, container: container) do
136
+ map :exclaim_all
137
+ end
138
+ }.to raise_error(ArgumentError)
139
+ end
140
+
141
+ context "before" do
142
+ let!(:new_transaction) {
143
+ initial_transaction.insert(before: :reverse, container: container) do
144
+ map :exclaim_all
145
+ end
146
+ }
147
+
148
+ it "inserts the new steps before the specified one" do
149
+ expect(new_transaction.call("hello world").right).to eq "!DLROW !OLLEH"
150
+ end
151
+
152
+ it "leaves the original transaction unmodified" do
153
+ expect(initial_transaction.call("hello world").right).to eq "DLROW OLLEH"
154
+ end
155
+ end
156
+
157
+ context "after" do
158
+ let!(:new_transaction) {
159
+ initial_transaction.insert(after: :reverse, container: container) do
160
+ map :exclaim_all
161
+ end
162
+ }
163
+
164
+ it "inserts the new steps after the specified one" do
165
+ expect(new_transaction.call("hello world").right).to eq "DLROW! OLLEH!"
166
+ end
167
+
168
+ it "leaves the original transaction unmodified" do
169
+ expect(initial_transaction.call("hello world").right).to eq "DLROW OLLEH"
170
+ end
171
+ end
172
+ end
173
+ end
metadata ADDED
@@ -0,0 +1,169 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dry-transaction
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0
5
+ platform: ruby
6
+ authors:
7
+ - Tim Riley
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: kleisli
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: wisper
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.6.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.6.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 10.4.2
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 10.4.2
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 3.3.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 3.3.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.10.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.10.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: yard
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
+ description:
112
+ email:
113
+ - tim@icelab.com.au
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - Gemfile
119
+ - Gemfile.lock
120
+ - LICENSE.md
121
+ - README.md
122
+ - Rakefile
123
+ - lib/dry-transaction.rb
124
+ - lib/dry/transaction.rb
125
+ - lib/dry/transaction/dsl.rb
126
+ - lib/dry/transaction/result_matcher.rb
127
+ - lib/dry/transaction/sequence.rb
128
+ - lib/dry/transaction/step.rb
129
+ - lib/dry/transaction/step_adapters.rb
130
+ - lib/dry/transaction/step_adapters/base.rb
131
+ - lib/dry/transaction/step_adapters/map.rb
132
+ - lib/dry/transaction/step_adapters/raw.rb
133
+ - lib/dry/transaction/step_adapters/tee.rb
134
+ - lib/dry/transaction/step_adapters/try.rb
135
+ - lib/dry/transaction/step_failure.rb
136
+ - lib/dry/transaction/version.rb
137
+ - spec/examples.txt
138
+ - spec/integration/passing_step_arguments_spec.rb
139
+ - spec/integration/publishing_step_events_spec.rb
140
+ - spec/integration/transaction_spec.rb
141
+ - spec/spec_helper.rb
142
+ - spec/support/test_module_constants.rb
143
+ - spec/unit/sequence_spec.rb
144
+ homepage: https://github.com/dry-rb/dry-transaction
145
+ licenses:
146
+ - MIT
147
+ metadata: {}
148
+ post_install_message:
149
+ rdoc_options: []
150
+ require_paths:
151
+ - lib
152
+ required_ruby_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: 2.0.0
157
+ required_rubygems_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ requirements: []
163
+ rubyforge_project:
164
+ rubygems_version: 2.5.1
165
+ signing_key:
166
+ specification_version: 4
167
+ summary: Business Transaction Flow DSL
168
+ test_files: []
169
+ has_rdoc: