Sha256: caa29bb94eb4459167540518089e417063057978bcc202edeaaaf67432ff0231

Contents?: true

Size: 1.58 KB

Versions: 71

Compression:

Stored size: 1.58 KB

Contents

Feature: be_within matcher

  Normal equality expectations do not work well for floating point values.
  Consider this irb session:

      > radius = 3
        => 3 
      > area_of_circle = radius * radius * Math::PI
        => 28.2743338823081 
      > area_of_circle == 28.2743338823081
        => false 

  Instead, you should use the be_within matcher to check that the value
  is within a delta of your expected value:

      area_of_circle.should be_within(0.1).of(28.3)

  Note that the difference between the actual and expected values must be
  smaller than your delta; if it is equal, the matcher will fail.

  Scenario: basic usage
    Given a file named "be_within_matcher_spec.rb" with:
      """
      describe 27.5 do
        it { should be_within(0.5).of(27.9) }
        it { should be_within(0.5).of(28.0) }
        it { should be_within(0.5).of(27.1) }
        it { should be_within(0.5).of(27.0) }

        it { should_not be_within(0.5).of(28.1) }
        it { should_not be_within(0.5).of(26.9) }

        # deliberate failures
        it { should_not be_within(0.5).of(28) }
        it { should_not be_within(0.5).of(27) }
        it { should be_within(0.5).of(28.1) }
        it { should be_within(0.5).of(26.9) }
      end
      """
    When I run `rspec be_within_matcher_spec.rb`
    Then the output should contain all of these:
      | 10 examples, 4 failures                     |
      | expected 27.5 not to be within 0.5 of 28   |
      | expected 27.5 not to be within 0.5 of 27   |
      | expected 27.5 to be within 0.5 of 28.1     |
      | expected 27.5 to be within 0.5 of 26.9     |

Version data entries

71 entries across 66 versions & 9 rubygems

Version Path
gem_repackager-0.1.0 support/gems/rspec-expectations-2.11.2/features/built_in_matchers/be_within.feature
classiccms-0.5.17 vendor/bundle/gems/rspec-expectations-2.10.0/features/built_in_matchers/be_within.feature
classiccms-0.5.16 vendor/bundle/gems/rspec-expectations-2.10.0/features/built_in_matchers/be_within.feature
classiccms-0.5.15 vendor/bundle/gems/rspec-expectations-2.10.0/features/built_in_matchers/be_within.feature
classiccms-0.5.14 vendor/bundle/gems/rspec-expectations-2.10.0/features/built_in_matchers/be_within.feature
classiccms-0.5.13 vendor/bundle/gems/rspec-expectations-2.10.0/features/built_in_matchers/be_within.feature
librarian-puppet-0.9.4 vendor/gems/ruby/1.8/gems/rspec-expectations-2.11.2/features/built_in_matchers/be_within.feature
rspec-expectations-2.11.3 features/built_in_matchers/be_within.feature
classiccms-0.5.12 vendor/bundle/gems/rspec-expectations-2.10.0/features/built_in_matchers/be_within.feature
classiccms-0.5.11 vendor/bundle/gems/rspec-expectations-2.10.0/features/built_in_matchers/be_within.feature
classiccms-0.5.10 vendor/bundle/gems/rspec-expectations-2.10.0/features/built_in_matchers/be_within.feature
classiccms-0.5.9 vendor/bundle/gems/rspec-expectations-2.10.0/features/built_in_matchers/be_within.feature
classiccms-0.5.8 vendor/bundle/gems/rspec-expectations-2.10.0/features/built_in_matchers/be_within.feature
librarian-puppet-0.9.3 vendor/gems/ruby/1.8/gems/rspec-expectations-2.11.2/features/built_in_matchers/be_within.feature
classiccms-0.5.7 vendor/bundle/gems/rspec-expectations-2.10.0/features/built_in_matchers/be_within.feature
classiccms-0.5.6 vendor/bundle/gems/rspec-expectations-2.10.0/features/built_in_matchers/be_within.feature
classiccms-0.5.5 vendor/bundle/gems/rspec-expectations-2.10.0/features/built_in_matchers/be_within.feature
classiccms-0.5.2 vendor/bundle/gems/rspec-expectations-2.10.0/features/built_in_matchers/be_within.feature
classiccms-0.5.1 vendor/bundle/gems/rspec-expectations-2.10.0/features/built_in_matchers/be_within.feature
classiccms-0.5.0 vendor/bundle/gems/rspec-expectations-2.10.0/features/built_in_matchers/be_within.feature