-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Beef up and restructure the RSpec suite to reduce duplication
- Loading branch information
1 parent
ef6d6b8
commit 764dfa4
Showing
12 changed files
with
400 additions
and
515 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
module PassFailExpectations | ||
def expect_pass(&block) | ||
expect(&block).not_to raise_error | ||
end | ||
|
||
def expect_fail(&block) | ||
expect(&block).to raise_error(RSpec::Expectations::ExpectationNotMetError) do |error| | ||
return error | ||
end | ||
end | ||
|
||
def expect_error(*args, &block) | ||
expect(&block).to raise_error(*args) do |error| | ||
return error | ||
end | ||
end | ||
end | ||
|
||
RSpec.configure do |config| | ||
config.include(PassFailExpectations) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
module RSpecShutdown | ||
def with_rspec_shutting_down_in(seconds) | ||
original_wants_to_quit = :unknown | ||
wants_to_quit_thread = | ||
Thread.new do | ||
sleep seconds | ||
original_wants_to_quit = RSpec.world.wants_to_quit | ||
RSpec.world.wants_to_quit = true | ||
end | ||
|
||
yield | ||
ensure | ||
wants_to_quit_thread&.kill | ||
RSpec.world.wants_to_quit = original_wants_to_quit unless original_wants_to_quit == :unknown | ||
end | ||
end | ||
|
||
RSpec.configure do |config| | ||
config.include(RSpecShutdown) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
class Ticker | ||
attr_reader :timeout, :tape | ||
|
||
def initialize(timeout:) | ||
@timeout = timeout | ||
@tape = "" | ||
end | ||
|
||
def start | ||
@ticking = | ||
Thread.new do | ||
timeout.times do | ||
sleep 1 | ||
@tape += "." | ||
end | ||
end | ||
end | ||
|
||
def length | ||
tape.length | ||
end | ||
|
||
def stop | ||
@ticking&.kill | ||
end | ||
end |
Oops, something went wrong.