mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Add RSpec change
matcher spec
This commit is contained in:
parent
e17435f6e8
commit
26656b7c12
1 changed files with 49 additions and 0 deletions
49
spec/rspec/expectations/change_matcher_spec.cr
Normal file
49
spec/rspec/expectations/change_matcher_spec.cr
Normal file
|
@ -0,0 +1,49 @@
|
|||
require "../../spec_helper"
|
||||
|
||||
# Examples taken from:
|
||||
# https://relishapp.com/rspec/rspec-expectations/v/3-8/docs/built-in-matchers/change-matcher
|
||||
# and modified to fit Spectator and Crystal.
|
||||
Spectator.describe "`change` matcher" do
|
||||
# Modified this example type to work in Crystal.
|
||||
module Counter
|
||||
extend self
|
||||
|
||||
@@count = 0
|
||||
|
||||
def increment
|
||||
@@count += 1
|
||||
end
|
||||
|
||||
def count
|
||||
@@count
|
||||
end
|
||||
end
|
||||
|
||||
context "expect change" do
|
||||
describe "Counter#increment" do # TODO: Allow multiple arguments to context/describe.
|
||||
it "should increment the count" do
|
||||
expect { Counter.increment }.to change { Counter.count }.from(0).to(1)
|
||||
end
|
||||
|
||||
# deliberate failure
|
||||
# TODO: Add support for expected failures.
|
||||
xit "should increment the count by 2" do
|
||||
expect { Counter.increment }.to change { Counter.count }.by(2)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "expect no change" do
|
||||
describe "Counter#increment" do # TODO: Allow multiple arguments to context/describe.
|
||||
# deliberate failures
|
||||
# TODO: Add support for expected failures.
|
||||
xit "should not increment the count by 1 (using not_to)" do
|
||||
expect { Counter.increment }.not_to change { Counter.count }
|
||||
end
|
||||
|
||||
xit "should not increment the count by 1 (using to_not)" do
|
||||
expect { Counter.increment }.to_not change { Counter.count }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue