Skip to content

Commit

Permalink
Make it a warning to overwrite (#13)
Browse files Browse the repository at this point in the history
* make it a warning to overwrite

* test that it did overwrite
  • Loading branch information
oxinabox authored Nov 12, 2018
1 parent c3cb2b9 commit 619d652
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
7 changes: 1 addition & 6 deletions src/ExpectationStubs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ struct ExpectationValueMismatchError <: Exception
end


struct ExpectationAlreadySetError <:Exception
name
sig
argvals
end

#########################################################

Expand Down Expand Up @@ -157,7 +152,7 @@ macro expect(defn)
###########################################################
# Check not already regeistered
if haskey($(esc(name)).expectations, $(argvals))
throw(ExpectationAlreadySetError($(esc(name)), $(sig), $(argvals)))
@warn "Expectation already set" name=$(Meta.quot(name)) argvals=$(argvals) sig=$(sig)
end


Expand Down
8 changes: 5 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
using ExpectationStubs
using ExpectationStubs: ExpectationValueMismatchError, ExpectationAlreadySetError
using ExpectationStubs: ExpectationValueMismatchError
using Test

using Test: @test_logs

@testset "basic stubbing" begin
@stub foo
@expect(foo(::Any)=32)
@test foo(3)==32
@test foo(4)==32
@test_throws ExpectationAlreadySetError @expect(foo(::Any)=34)

@test_logs (:warn, "Expectation already set") @expect(foo(::Any)=34)
@test foo(5)==34
end

@testset "multitype stubbing" begin
Expand Down

0 comments on commit 619d652

Please sign in to comment.