-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
210 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# fibonacci.rb | ||
class Fibonacci | ||
def self.calculate(n) | ||
raise ArgumentError, "Input must be a non-negative integer." unless n.is_a?(Integer) && n >= 0 | ||
return n if n <= 1 | ||
|
||
a, b = 0, 1 | ||
(n - 1).times { a, b = b, a + b } | ||
b | ||
end | ||
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
require 'retest' | ||
require_relative 'support/test_helper' | ||
require 'minitest/autorun' | ||
require_relative 'retest_test/file_changes_test' | ||
# require_relative 'retest_test/file_changes_test' | ||
require_relative 'retest_test/interactive_commands_test' | ||
|
||
$stdout.sync = true |
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
125 changes: 125 additions & 0 deletions
125
features/bundler-app/retest/retest_test/interactive_commands_test.rb
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,125 @@ | ||
class InteractiveCommandTest < Minitest::Test | ||
include FileHelper | ||
include InputHelper | ||
include OutputHelper | ||
include CommandHelper | ||
include AssertionsHelper | ||
|
||
def setup | ||
@command = 'retest' | ||
end | ||
|
||
def teardown | ||
end_retest | ||
end | ||
|
||
def test_start_help_exit | ||
launch_retest @command | ||
|
||
assert_output_matches <<~EXPECTED.chomp | ||
Setup identified: [RAKE]. Using command: 'bundle exec rake test TEST=<test>' | ||
Watcher: [LISTEN] | ||
Launching Retest... | ||
Ready to refactor! You can make file changes now | ||
Type interactive command and press enter. Enter 'h' for help. | ||
>\s | ||
EXPECTED | ||
|
||
write_input("h\n") | ||
|
||
assert_output_matches <<~EXPECTED.chomp | ||
* 'h', 'help' # Prints help. | ||
* 'p', 'pause' # Pauses Retest. Tests aren't run on file change events until unpaused. | ||
* 'u', 'unpause' # Unpauses Retest. | ||
* <ENTER> # Runs last changed triggered command. | ||
* 'ra, 'run all' # Runs all tests. | ||
* 'f', 'force' # Forces a selection of test to run on every file change. | ||
* 'r', 'reset' # Disables forced selection. | ||
* 'd', 'diff' [GIT BRANCH] # Runs matching specs that changed from a target branch. | ||
* 'e', 'exit' # Exits Retest. | ||
Type interactive command and press enter. Enter 'h' for help. | ||
>\s | ||
EXPECTED | ||
end | ||
|
||
def test_pause_unpause_retest | ||
launch_retest @command | ||
|
||
modify_file('lib/bundler_app/bottles.rb') | ||
|
||
assert_output_matches( | ||
"Test file: test/bundler_app/test_bottles.rb", | ||
"12 runs, 12 assertions, 0 failures, 0 errors, 0 skips" | ||
) | ||
|
||
write_input("p\n") | ||
|
||
assert_output_matches "Program is paused" | ||
|
||
modify_file('lib/bundler_app/bottles.rb') | ||
|
||
assert_output_matches <<~EXPECTED | ||
File changed: lib/bundler_app/bottles.rb | ||
Main program paused. Please resume program first. | ||
EXPECTED | ||
|
||
write_input("u\n") | ||
|
||
modify_file('lib/bundler_app/bottles.rb') | ||
|
||
assert_output_matches( | ||
"Test file: test/bundler_app/test_bottles.rb", | ||
"12 runs, 12 assertions, 0 failures, 0 errors, 0 skips" | ||
) | ||
end | ||
|
||
def test_force_a_file_to_run | ||
launch_retest @command | ||
|
||
write_input("f\n") | ||
|
||
assert_output_matches "What test files do you want to run when saving a file? (min. 1)" | ||
|
||
write_input("fib\s\n") | ||
|
||
assert_output_matches <<~EXPECTED | ||
Forced selection enabled. | ||
Reset to default settings by typing 'r' in the interactive console. | ||
Tests selected: | ||
- test/bundler_app/test_fibonacci.rb | ||
EXPECTED | ||
|
||
assert_output_matches "8 runs, 9 assertions, 0 failures, 0 errors, 0 skips" | ||
|
||
modify_file('lib/bundler_app/bottles.rb') | ||
|
||
assert_output_matches <<~EXPECTED | ||
Forced selection enabled. | ||
Reset to default settings by typing 'r' in the interactive console. | ||
Tests selected: | ||
- test/bundler_app/test_fibonacci.rb | ||
EXPECTED | ||
|
||
write_input("r\n") | ||
|
||
modify_file('lib/bundler_app/bottles.rb') | ||
|
||
assert_output_matches( | ||
"Test file: test/bundler_app/test_bottles.rb", | ||
"12 runs, 12 assertions, 0 failures, 0 errors, 0 skips") | ||
end | ||
|
||
def test_run_all | ||
launch_retest @command | ||
|
||
write_input("ra\n") | ||
|
||
assert_output_matches( | ||
"Running all tests", | ||
"21 runs, 21 assertions, 0 failures, 0 errors, 0 skips") | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
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,40 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'test_helper' | ||
|
||
module BundlerApp | ||
class FibonacciTest < Minitest::Test | ||
def test_fibonacci_zero | ||
assert_equal 0, Fibonacci.calculate(0) | ||
end | ||
|
||
def test_fibonacci_one | ||
assert_equal 1, Fibonacci.calculate(1) | ||
end | ||
|
||
def test_fibonacci_two | ||
assert_equal 1, Fibonacci.calculate(2) | ||
end | ||
|
||
def test_fibonacci_five | ||
assert_equal 5, Fibonacci.calculate(5) | ||
end | ||
|
||
def test_fibonacci_ten | ||
assert_equal 55, Fibonacci.calculate(10) | ||
end | ||
|
||
def test_large_fibonacci | ||
assert_equal 6765, Fibonacci.calculate(20) # Example large Fibonacci number | ||
end | ||
|
||
def test_invalid_input_negative | ||
assert_raises(ArgumentError) { Fibonacci.calculate(-1) } | ||
end | ||
|
||
def test_invalid_input_non_integer | ||
assert_raises(ArgumentError) { Fibonacci.calculate(2.5) } | ||
assert_raises(ArgumentError) { Fibonacci.calculate("five") } | ||
end | ||
end | ||
end |