Skip to content

Commit

Permalink
move internal assertions.
Browse files Browse the repository at this point in the history
  • Loading branch information
apotonick committed Jan 21, 2025
1 parent b55def4 commit 9388266
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
19 changes: 0 additions & 19 deletions test/suite_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -331,25 +331,6 @@ def model(ctx, params:, **)
end
end

def assert_test_case_passes(test, number, input)
test_case = test.new(:"test_00#{number}_anonymous")
failures, assertions, result = test_case.()

puts failures if failures.size > 0 # TODO: this is an automatic "debugger" :D
assert_equal failures.size, 0
# assert_equal assertions, assertion_count

assert_equal result[:captured], input
end

def assert_test_case_fails(test, number, error_message)
test_case = test.new(:"test_00#{number}_anonymous")
failures, assertions, _ = test_case.()

assert_equal failures.size, 1
assert_equal failures[0].inspect, error_message
end

# assert_pass {}, {}
assert_test_case_passes(test, "01", input = %({:params=>{:memo=>{:title=>\"Note to self\", :content=>\"Remember me!\"}}}))
assert_test_case_fails(test, "02", %(#<Minitest::Assertion: {Trailblazer::Test::Testing::Memo::Operation::Create} failed: \e[33m{:title=>[\"must be filled\"]}\e[0m.
Expand Down
22 changes: 21 additions & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,26 @@
require "trailblazer/test/testing" # {Song} and {Song::Operation::Create} etc
require "trailblazer/core"

Activity = Trailblazer::Activity
Testing = Trailblazer::Activity::Testing
CU = Trailblazer::Core::Utils

Minitest::Spec.class_eval do
def assert_test_case_passes(test, number, input)
test_case = test.new(:"test_00#{number}_anonymous")
failures, assertions, result = test_case.()

puts failures if failures.size > 0 # TODO: this is an automatic "debugger" :D
assert_equal failures.size, 0
# assert_equal assertions, assertion_count

assert_equal result[:captured], input
end

def assert_test_case_fails(test, number, error_message)
test_case = test.new(:"test_00#{number}_anonymous")
failures, assertions, _ = test_case.()

assert_equal failures.size, 1
assert_equal failures[0].inspect, error_message
end
end

0 comments on commit 9388266

Please sign in to comment.