From 49a35c268c0808a0ac948ba20a3d447145336a1c Mon Sep 17 00:00:00 2001 From: Ryan Faerman Date: Mon, 21 Jul 2014 20:18:07 -0400 Subject: [PATCH] Add the "failure?" method to the outcome The failure? method helps consumers of the mutations add some clarity. --- lib/mutations/outcome.rb | 4 ++++ spec/command_spec.rb | 16 ++++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/mutations/outcome.rb b/lib/mutations/outcome.rb index 177e039..10585eb 100644 --- a/lib/mutations/outcome.rb +++ b/lib/mutations/outcome.rb @@ -9,5 +9,9 @@ def initialize(is_success, result, errors, inputs) def success? @success end + + def failure? + !success? + end end end diff --git a/spec/command_spec.rb b/spec/command_spec.rb index 78679a0..e0ba0fb 100644 --- a/spec/command_spec.rb +++ b/spec/command_spec.rb @@ -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 @@ -45,7 +45,7 @@ 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 @@ -53,14 +53,14 @@ 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 @@ -68,7 +68,7 @@ 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 @@ -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 @@ -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 @@ -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]