Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/mutations/outcome.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@ def initialize(is_success, result, errors, inputs)
def success?
@success
end

def failure?
!success?
end
end
end
16 changes: 8 additions & 8 deletions spec/command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
it "should discover errors in inputs" do
outcome = SimpleCommand.run(:name => "JohnTooLong", :email => "john@gmail.com")

assert !outcome.success?
assert outcome.failure?
assert_equal :max_length, outcome.errors.symbolic[:name]
end

Expand All @@ -45,30 +45,30 @@
assert_nil outcome.errors

outcome = SimpleCommand.validate(:name => "JohnTooLong", :email => "john@gmail.com")
assert !outcome.success?
assert outcome.failure?
assert_nil outcome.result
assert_equal :max_length, outcome.errors.symbolic[:name]
end

it "should execute a custom validate method" do
outcome = SimpleCommand.validate(:name => "JohnLong", :email => "xxxx")

assert !outcome.success?
assert outcome.failure?
assert_equal :invalid, outcome.errors.symbolic[:email]
end

it "should execute custom validate method during run" do
outcome = SimpleCommand.run(:name => "JohnLong", :email => "xxxx")

assert !outcome.success?
assert outcome.failure?
assert_nil outcome.result
assert_equal :invalid, outcome.errors.symbolic[:email]
end

it "should execute custom validate method only if regular validations succeed" do
outcome = SimpleCommand.validate(:name => "JohnTooLong", :email => "xxxx")

assert !outcome.success?
assert outcome.failure?
assert_equal :max_length, outcome.errors.symbolic[:name]
assert_equal nil, outcome.errors.symbolic[:email]
end
Expand Down Expand Up @@ -162,7 +162,7 @@ def execute
it "should let you add errors" do
outcome = ErrorfulCommand.run(:name => "John", :email => "john@gmail.com")

assert !outcome.success?
assert outcome.failure?
assert_nil outcome.result
assert :is_a_bob, outcome.errors.symbolic[:bob]
end
Expand All @@ -184,7 +184,7 @@ def execute
it "should let you add errors nested under a namespace" do
outcome = NestingErrorfulCommand.run(:name => "John", :email => "john@gmail.com")

assert !outcome.success?
assert outcome.failure?
assert_nil outcome.result
assert :is_a_bob, outcome.errors[:people].symbolic[:bob]
end
Expand All @@ -210,7 +210,7 @@ def execute
it "should let you merge errors" do
outcome = ErrorfulCommand.run(:name => "John", :email => "john@gmail.com")

assert !outcome.success?
assert outcome.failure?
assert_nil outcome.result
assert :is_short, outcome.errors.symbolic[:bob]
assert :is_fat, outcome.errors.symbolic[:sally]
Expand Down