Skip to content

Commit

Permalink
add specs
Browse files Browse the repository at this point in the history
  • Loading branch information
markburns committed Jan 6, 2024
1 parent a906e09 commit e545af9
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 9 deletions.
Empty file removed spec/fixtures/asdf
Empty file.
20 changes: 19 additions & 1 deletion spec/fixtures/integration_app/app/interactors/all_the_things.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
# Note: The conditional structures (`if`, `each`) here are not executed at runtime in the usual
# sense. They are evaluated when defining the organizer, leading to the creation of discrete
# classes that handle the respective logic.
#

require_relative './organizing/organized1'
require_relative './organizing/organized2'

class AllTheThings
include Interactify

Expand All @@ -46,6 +49,21 @@ class AllTheThings
else: [If::C, If::D]
),

# test nested promises
chain(
:nested_promises,
Organizing::Organized1.promising(
:organized1_called
),
Organizing::Organized2.organizing(
Organizing::DeeplyNestedInteractor,
Organizing::DeeplyNestedPromisingInteractor.promising(
:deeply_nested_promising_interactor_called
),
Organizing::Organized2::Organized2Called
)
),

# test each with lambda
self.if(
-> (c) { c.things },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ class Organized2
include Interactify

organize(
DeeplyNestedInteractor,
DeeplyNestedPromisingInteractor.promising(
:deeply_nested_promising_interactor_called
),
Organized2Called = Interactify do |context|
context.organized2_called = true
end
)
DeeplyNestedInteractor,
DeeplyNestedPromisingInteractor.promising(
:deeply_nested_promising_interactor_called
),
Organized2Called = Interactify do |context|
context.organized2_called = true
end
)
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require_relative './organizing/organized1'
require_relative './organizing/organized2'

class UnfulfilledPromises
include Interactify

expect :dont_fulfill, filled: false
expect :things
promise :something_unfulfilled
promise :another_thing

organize each(
:things,
{
if: :dont_fulfill,
then: chain(
:nested_promises,
each(
:things,
Organizing::Organized1.promising(
:organized1_called
),
SetAnothingThing = Interactify { _1.another_thing = true },

Organizing::Organized2.organizing(
Organizing::DeeplyNestedInteractor,
Organizing::DeeplyNestedPromisingInteractor.promising(
:deeply_nested_promising_interactor_called
),
Organizing::Organized2::Organized2Called
)
)
),
else: DoSomethingElse = Interactify { _1.something_unfulfilled = true }
}
)
end
84 changes: 84 additions & 0 deletions spec/integration/unfulfilled_promise_integration_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# frozen_string_literal: true

RSpec.describe "Unfulfilled promises" do
let(:result) { klass.call(things:, dont_fulfill:, another_thing:) }
let(:another_thing) { true }

let(:klass) do
UnfulfilledPromises.promising(:something_unfulfilled, :another_thing)
end

let(:things) do
[thing1, thing2]
end

let(:thing1) do
OpenStruct.new
end

let(:thing2) do
OpenStruct.new
end

before do
require "./spec/fixtures/integration_app/app/interactors/unfulfilled_promises"
end

context "when calling with call" do
let(:result) { klass.call(things:, dont_fulfill:, another_thing:) }

context "when not fulfilling" do
let(:dont_fulfill) { true }

it "does not raise" do
expect { result }.not_to raise_error

expect(result.contract_failures).to eq(
{ something_unfulfilled: ["something_unfulfilled is missing"] }
)
end
end

context "when fulfilling" do
let(:dont_fulfill) { false }

it "does not raise" do
expect { result }.not_to raise_error

but_expect_irony
end
end
end

context "when calling with call!" do
let(:result) { klass.call!(things:, dont_fulfill:, another_thing:) }

context "when not fulfilling" do
let(:dont_fulfill) { true }

it "raises" do
expect { result }
.to raise_error do |error|
expect(error).to be_a UnfulfilledPromises::InteractorContractFailure
expect(error.message).to eq(
{ something_unfulfilled: ["something_unfulfilled is missing"] }.to_json
)
end
end
end

context "when fulfilling" do
let(:dont_fulfill) { false }

it "does not raise" do
expect { result }.not_to raise_error

but_expect_irony
end
end
end

def but_expect_irony
expect(result.something_unfulfilled).to eq(true)
end
end

0 comments on commit e545af9

Please sign in to comment.