mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Add specs of snippets from docs
This commit is contained in:
parent
0322d5bd28
commit
5c24d606dd
7 changed files with 382 additions and 0 deletions
57
spec/docs/helper_methods_spec.cr
Normal file
57
spec/docs/helper_methods_spec.cr
Normal file
|
@ -0,0 +1,57 @@
|
|||
Spectator.describe String do
|
||||
# This is a helper method.
|
||||
def random_string(length)
|
||||
chars = ('a'..'z').to_a
|
||||
String.build(length) do |builder|
|
||||
length.times { builder << chars.sample }
|
||||
end
|
||||
end
|
||||
|
||||
describe "#size" do
|
||||
subject { random_string(10).size }
|
||||
|
||||
it "is the length of the string" do
|
||||
is_expected.to eq(10)
|
||||
end
|
||||
end
|
||||
end
|
||||
Spectator.describe String do
|
||||
# length is now pulled from value defined by `let`.
|
||||
def random_string
|
||||
chars = ('a'..'z').to_a
|
||||
String.build(length) do |builder|
|
||||
length.times { builder << chars.sample }
|
||||
end
|
||||
end
|
||||
|
||||
describe "#size" do
|
||||
let(length) { 10 } # random_string uses this.
|
||||
subject { random_string.size }
|
||||
|
||||
it "is the length of the string" do
|
||||
is_expected.to eq(length)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module StringHelpers
|
||||
def random_string
|
||||
chars = ('a'..'z').to_a
|
||||
String.build(length) do |builder|
|
||||
length.times { builder << chars.sample }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Spectator.describe String do
|
||||
include StringHelpers
|
||||
|
||||
describe "#size" do
|
||||
let(length) { 10 }
|
||||
subject { random_string.size }
|
||||
|
||||
it "is the length of the string" do
|
||||
is_expected.to eq(length)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue