Skip to content

Commit

Permalink
Move expectations so that Bridgetown::Test can access it too
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredcwhite committed Dec 16, 2024
1 parent e5ff91c commit 7914c86
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 64 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# frozen_string_literal: true

module Bridgetown
# This is for including into Minitest::Expectation
module IntuitiveExpectations
def true?(msg = nil)
must_be(:itself, Minitest::Assertions::UNDEFINED, msg)
self
end

def false?(msg = nil)
wont_be(:itself, Minitest::Assertions::UNDEFINED, msg)
self
end

def ==(other)
must_equal(other)
self
end

def !=(other)
must_not_equal(other)
self
end

def nil?(msg = nil)
must_be_nil(msg)
self
end

def not_nil?(msg = nil)
wont_be_nil(msg)
self
end

def empty?(msg = nil)
must_be_empty(msg)
self
end

def filled?(msg = nil)
wont_be_empty(msg)
self
end

def include?(other, msg = nil)
must_include(other, msg)
self
end
alias_method :<<, :include?

def exclude?(other, msg = nil)
wont_include(other, msg)
self
end

def =~(other)
must_match(other)
self
end

def is_a?(klass, msg = nil)
must_be_instance_of(klass, msg)
self
end
end
end
67 changes: 3 additions & 64 deletions bridgetown-core/test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,70 +69,9 @@ def refute_file_contains(regex, filename)
end
end

module IntuitiveExpectations
def true?(msg = nil)
must_be(:itself, Minitest::Assertions::UNDEFINED, msg)
self
end

def false?(msg = nil)
wont_be(:itself, Minitest::Assertions::UNDEFINED, msg)
self
end

def ==(other)
must_equal(other)
self
end

def !=(other)
must_not_equal(other)
self
end

def nil?(msg = nil)
must_be_nil(msg)
self
end

def not_nil?(msg = nil)
wont_be_nil(msg)
self
end

def empty?(msg = nil)
must_be_empty(msg)
self
end

def filled?(msg = nil)
wont_be_empty(msg)
self
end

def include?(other, msg = nil)
must_include(other, msg)
self
end
alias_method :<<, :include?

def exclude?(other, msg = nil)
wont_include(other, msg)
self
end

def =~(other)
must_match(other)
self
end

def is_a?(klass, msg = nil)
must_be_instance_of(klass, msg)
self
end
end
Minitest::Expectation.include IntuitiveExpectations
Minitest.backtrace_filter.add_filter %r!bridgetown-core/test/helper\.rb!
require "bridgetown-core/concerns/intuitive_expectations"
Minitest::Expectation.include Bridgetown::IntuitiveExpectations
Minitest.backtrace_filter.add_filter %r!bridgetown-core/concerns/intuitive_expectations\.rb!

module DirectoryHelpers
def root_dir(*subdirs)
Expand Down
4 changes: 4 additions & 0 deletions bridgetown/lib/bridgetown/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@

require "rack/test"

require "bridgetown-core/concerns/intuitive_expectations"
Minitest::Expectation.include Bridgetown::IntuitiveExpectations
Minitest.backtrace_filter.add_filter %r!bridgetown-core/concerns/intuitive_expectations\.rb!

class Bridgetown::Test < Minitest::Test
include Minitest::Spec::DSL::InstanceMethods
include Rack::Test::Methods
Expand Down

0 comments on commit 7914c86

Please sign in to comment.