Skip to content

Commit

Permalink
docs(README): use x.positive? instead of x > 0
Browse files Browse the repository at this point in the history
  • Loading branch information
cyril committed Dec 29, 2024
1 parent 1bd4eb5 commit 90d1c46
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 57 deletions.
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ Here is the collection of generic matchers.
##### `Be`
Checks for object identity using Ruby's `equal?` method.
```ruby
Matchi::Be.new(:foo).match? { :foo } # => true (same object)
Matchi::Be.new("test").match? { "test" } # => false (different objects)
Matchi::Be.new(:foo).match? { :foo } # => true (same object)
Matchi::Be.new("test").match? { "test" } # => false (different objects)
```

##### `Eq`
Verifies object equivalence using Ruby's `eql?` method.
```ruby
Matchi::Eq.new("foo").match? { "foo" } # => true (equivalent content)
Matchi::Eq.new([1, 2]).match? { [1, 2] } # => true (equivalent arrays)
Matchi::Eq.new("foo").match? { "foo" } # => true (equivalent content)
Matchi::Eq.new([1, 2]).match? { [1, 2] } # => true (equivalent arrays)
```

#### Type and Class Matchers
Expand Down Expand Up @@ -113,8 +113,8 @@ Matchi::Match.new(/^foo/).match? { "barfoo" } # => false
##### `Satisfy`
Provides custom matching through a block.
```ruby
Matchi::Satisfy.new { |x| x > 0 && x < 10 }.match? { 5 } # => true
Matchi::Satisfy.new { |x| x.start_with?("test") }.match? { "test_file" } # => true
Matchi::Satisfy.new { |x| x.positive? && x < 10 }.match? { 5 } # => true
Matchi::Satisfy.new { |x| x.start_with?("test") }.match? { "test_file" } # => true
```

#### State Change Matchers
Expand All @@ -125,31 +125,31 @@ Verifies state changes in objects with multiple variation methods:
###### Basic Change
```ruby
array = []
Matchi::Change.new(array, :length).by(2).match? { array.push(1, 2) } # => true
Matchi::Change.new(array, :length).by(2).match? { array.push(1, 2) } # => true
```

###### Minimum Change
```ruby
counter = 0
Matchi::Change.new(counter, :to_i).by_at_least(2).match? { counter += 3 } # => true
Matchi::Change.new(counter, :to_i).by_at_least(2).match? { counter += 3 } # => true
```

###### Maximum Change
```ruby
value = 10
Matchi::Change.new(value, :to_i).by_at_most(5).match? { value += 3 } # => true
Matchi::Change.new(value, :to_i).by_at_most(5).match? { value += 3 } # => true
```

###### From-To Change
```ruby
string = "hello"
Matchi::Change.new(string, :upcase).from("hello").to("HELLO").match? { string.upcase! } # => true
Matchi::Change.new(string, :upcase).from("hello").to("HELLO").match? { string.upcase! } # => true
```

###### To-Only Change
```ruby
number = 1
Matchi::Change.new(number, :to_i).to(5).match? { number = 5 } # => true
Matchi::Change.new(number, :to_i).to(5).match? { number = 5 } # => true
```

#### Numeric Matchers
Expand All @@ -166,8 +166,8 @@ Matchi::BeWithin.new(5).of(100).match? { 98 } # => true
##### `RaiseException`
Verifies that code raises specific exceptions.
```ruby
Matchi::RaiseException.new(ArgumentError).match? { raise ArgumentError } # => true
Matchi::RaiseException.new(NameError).match? { undefined_variable } # => true
Matchi::RaiseException.new(ArgumentError).match? { raise ArgumentError } # => true
Matchi::RaiseException.new(NameError).match? { undefined_variable } # => true
```

##### `Predicate`
Expand All @@ -181,7 +181,7 @@ Matchi::Predicate.new(:be_nil).match? { nil } # => true (calls nil?)

###### Using `have_` prefix
```ruby
Matchi::Predicate.new(:have_key, :foo).match? { { foo: 42 } } # => true (calls has_key?)
Matchi::Predicate.new(:have_key, :foo).match? { { foo: 42 } } # => true (calls has_key?)
```

### Custom matchers
Expand Down Expand Up @@ -288,7 +288,7 @@ This is why Matchi's built-in matchers are implemented with this security consid
```ruby
# Implementation in Matchi::Eq
def match?
@expected.eql?(yield) # Expected value controls the comparison
@expected.eql?(yield) # Expected value controls the comparison
end
```

Expand Down
3 changes: 0 additions & 3 deletions test/test_be.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,3 @@

# It returns this string
raise unless matcher.to_s == "be :foo"

# It returns this representation
raise unless matcher.inspect == "Matchi::Be(:foo)"
1 change: 0 additions & 1 deletion test/test_be_a_kind_of.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

# Test string representations
raise unless matcher.to_s == "be a kind of String"
raise unless matcher.inspect == "Matchi::BeAKindOf(String)"

# Test with symbol class name
matcher = Matchi::BeAKindOf.new(:String)
Expand Down
1 change: 0 additions & 1 deletion test/test_be_an_instance_of.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class CustomClass; end # rubocop:disable Lint/EmptyClass

# Test string representations
raise unless matcher.to_s == "be an instance of String"
raise unless matcher.inspect == "Matchi::BeAnInstanceOf(String)"

# Test with symbol class name
matcher = Matchi::BeAnInstanceOf.new(:String)
Expand Down
3 changes: 0 additions & 3 deletions test/test_be_within.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,3 @@

# It returns this string
raise unless matcher.to_s == "be within 1 of 41"

# It returns this representation
raise unless matcher.inspect == "Matchi::BeWithin::Of(1, 41)"
15 changes: 0 additions & 15 deletions test/test_change.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
# It returns this string
raise unless matcher.to_s == "change by 2"

# It returns this representation
raise unless matcher.inspect == "Matchi::Change::By(2)"

object = []
matcher = Matchi::Change.new(object, :length).by_at_least(2)

Expand All @@ -33,9 +30,6 @@
# It returns this string
raise unless matcher.to_s == "change by at least 2"

# It returns this representation
raise unless matcher.inspect == "Matchi::Change::ByAtLeast(2)"

object = []
matcher = Matchi::Change.new(object, :length).by_at_most(1)

Expand All @@ -49,9 +43,6 @@
# It returns this string
raise unless matcher.to_s == "change by at most 1"

# It returns this representation
raise unless matcher.inspect == "Matchi::Change::ByAtMost(1)"

object = "foo"
matcher = Matchi::Change.new(object, :to_s).from("foo").to("FOO")

Expand All @@ -64,9 +55,6 @@
# It returns this string
raise unless matcher.to_s == 'change from "foo" to "FOO"'

# It returns this representation
raise unless matcher.inspect == 'Matchi::Change::From::To("foo", "FOO")'

object = "foo"
matcher = Matchi::Change.new(object, :to_s).to("FOO")

Expand All @@ -78,6 +66,3 @@

# It returns this string
raise unless matcher.to_s == 'change to "FOO"'

# It returns this representation
raise unless matcher.inspect == 'Matchi::Change::To("FOO")'
3 changes: 0 additions & 3 deletions test/test_eq.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,3 @@

# It returns this string
raise unless matcher.to_s == 'eq "foo"'

# It returns this representation
raise unless matcher.inspect == 'Matchi::Eq("foo")'
3 changes: 0 additions & 3 deletions test/test_match.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,3 @@

# It returns this string
raise unless matcher.to_s == "match /^foo/"

# It returns this representation
raise unless matcher.inspect == "Matchi::Match(/^foo/)"
9 changes: 0 additions & 9 deletions test/test_predicate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
# It returns this string
raise unless matcher.to_s == "be empty"

# It returns this representation
raise unless matcher.inspect == "Matchi::Predicate(be_empty, *[], **{}, &nil)"

matcher = Matchi::Predicate.new("have_key", :foo)

# It is expected to be true
Expand All @@ -28,9 +25,6 @@
# It returns this string
raise unless matcher.to_s == "have key :foo"

# It returns this representation
raise unless matcher.inspect == "Matchi::Predicate(have_key, *[:foo], **{}, &nil)"

matcher = Matchi::Predicate.new(:be_swimmer, foo: "bar")

class Duck
Expand All @@ -54,6 +48,3 @@ def swimmer?(**_options)
# It returns this string

raise unless matcher.to_s == 'be swimmer foo: "bar"'

# It returns this representation
raise unless matcher.inspect == 'Matchi::Predicate(be_swimmer, *[], **{:foo=>"bar"}, &nil)'
1 change: 0 additions & 1 deletion test/test_raise_exception.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ class NestedError < StandardError; end

matcher = Matchi::RaiseException.new(:CustomError)
raise unless matcher.to_s == "raise exception CustomError"
raise unless matcher.inspect == "Matchi::RaiseException(CustomError)"

#
# Test exception messages
Expand Down
3 changes: 0 additions & 3 deletions test/test_satisfy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,3 @@

# It returns this string
raise unless matcher.to_s == "satisfy &block"

# It returns this representation
raise unless matcher.inspect == "Matchi::Satisfy(&block)"

0 comments on commit 90d1c46

Please sign in to comment.