mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Add helper method specs from RSpec docs
This commit is contained in:
parent
b1984b343a
commit
3d08949c94
2 changed files with 74 additions and 0 deletions
29
spec/rspec/core/helper_methods_spec.cr
Normal file
29
spec/rspec/core/helper_methods_spec.cr
Normal file
|
@ -0,0 +1,29 @@
|
|||
require "../../spec_helper"
|
||||
|
||||
Spectator.describe "Arbitrary helper methods" do
|
||||
context "Use a method define in the same group" do
|
||||
describe "an example" do
|
||||
def help
|
||||
:available
|
||||
end
|
||||
|
||||
it "has access to methods define in its group" do
|
||||
expect(help).to eq(:available) # TODO: `be` matcher with value (no same? method).
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "Use a method defined in a parent group" do
|
||||
describe "an example" do
|
||||
def help
|
||||
:available
|
||||
end
|
||||
|
||||
describe "in a nested group" do
|
||||
it "has access to methods defined in its parent group" do
|
||||
expect(help).to eq(:available) # TODO: `be` matcher with value (no same? method).
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
45
spec/rspec/core/let_spec.cr
Normal file
45
spec/rspec/core/let_spec.cr
Normal file
|
@ -0,0 +1,45 @@
|
|||
require "../../spec_helper"
|
||||
|
||||
# Examples taken from:
|
||||
# https://relishapp.com/rspec/rspec-core/v/3-8/docs/helper-methods/let-and-let
|
||||
# and modified to fit Spectator and Crystal.
|
||||
Spectator.describe "Let and let!" do
|
||||
context "Use `let` to define memoized helper method" do
|
||||
# Globals aren't supported, use class variables instead.
|
||||
@@count = 0
|
||||
|
||||
describe "let" do
|
||||
let(:count) { @@count += 1 }
|
||||
|
||||
it "memoizes thte value" do
|
||||
expect(count).to eq(1)
|
||||
expect(count).to eq(1)
|
||||
end
|
||||
|
||||
it "is not cached across examples" do
|
||||
expect(count).to eq(2)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "Use `let!` to define a memoized helper method that is called in a `before` hook" do
|
||||
# Globals aren't supported, use class variables instead.
|
||||
@@count = 0
|
||||
|
||||
describe "let!" do
|
||||
# Use class variable here.
|
||||
@@invocation_order = [] of Symbol
|
||||
|
||||
let!(:count) do
|
||||
@@invocation_order << :let!
|
||||
@@count += 1
|
||||
end
|
||||
|
||||
it "calls the helper method in a before hook" do
|
||||
@@invocation_order << :example
|
||||
expect(@@invocation_order).to eq([:let!, :example])
|
||||
expect(count).to eq(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue