Skip to content

Commit

Permalink
Improving the deprecation warning, making the message optional arg
Browse files Browse the repository at this point in the history
It was hard for me to switch to the new methods, improved the deprecation warning by telling what method needs to be changed to the new name.
  • Loading branch information
adomokos committed Feb 25, 2014
1 parent 552e7db commit fc70432
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/light-service/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,26 @@ def skip_all?
end

def set_success!(message)
warn 'DEPRECATED: Please use `succeed!` instead'
warn '`set_success!` is DEPRECATED: please use `succeed!` instead'
succeed!(message)
end

def succeed!(message)
def succeed!(message=nil)
@message = message
@outcome = ::LightService::Outcomes::SUCCESS
end

def set_failure!(message)
warn 'DEPRECATED: Please use `fail!` instead'
warn '`set_failure!` is DEPRECATED: please use `fail!` instead'
fail!(message)
end

def fail!(message)
def fail!(message=nil)
@message = message
@outcome = ::LightService::Outcomes::FAILURE
end

def skip_all!(message = nil)
def skip_all!(message=nil)
@message = message
@skip_all = true
end
Expand Down
14 changes: 14 additions & 0 deletions spec/context_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,26 @@ module LightService
expect(context).to be_success
end

it "can be pushed into a SUCCESS state without a message" do
context = Context.make
context.succeed!
expect(context).to be_success
expect(context.message).to be_nil
end

it "can be pushed into a FAILURE state" do
context = Context.make
context.fail!("a sad end")
expect(context).to be_failure
end

it "can be pushed into a FAILURE state without a message" do
context = Context.make
context.fail!
expect(context).to be_failure
expect(context.message).to be_nil
end

it "can set a flag to skip all subsequent actions" do
context = Context.make
context.skip_all!
Expand Down

0 comments on commit fc70432

Please sign in to comment.