Sha256: 113a4fded7f95f87bde69a285b7c1c28bbc66a25dae2fb2a41125a5a2cb5e0fb

Contents?: true

Size: 1.6 KB

Versions: 35

Compression:

Stored size: 1.6 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:

    ```ruby
    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:
      """ruby
      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

35 entries across 35 versions & 8 rubygems

Version Path
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.4.0/gems/rspec-expectations-2.14.5/features/built_in_matchers/be_within.feature
vagrant-unbundled-1.9.5.1 vendor/bundle/ruby/2.4.0/gems/rspec-expectations-2.14.5/features/built_in_matchers/be_within.feature
vagrant-unbundled-1.9.1.1 vendor/bundle/ruby/2.4.0/gems/rspec-expectations-2.14.5/features/built_in_matchers/be_within.feature
vagrant-unbundled-1.8.5.2 vendor/bundle/ruby/2.3.0/gems/rspec-expectations-2.14.5/features/built_in_matchers/be_within.feature
vagrant-unbundled-1.8.5.1 vendor/bundle/ruby/2.3.0/gems/rspec-expectations-2.14.5/features/built_in_matchers/be_within.feature
vagrant-unbundled-1.8.4.2 vendor/bundle/ruby/2.3.0/gems/rspec-expectations-2.14.5/features/built_in_matchers/be_within.feature
vagrant-unbundled-1.8.4.1 vendor/bundle/ruby/2.3.0/gems/rspec-expectations-2.14.5/features/built_in_matchers/be_within.feature
vagrant-unbundled-1.8.1.1 vendor/bundle/ruby/2.3.0/gems/rspec-expectations-2.14.5/features/built_in_matchers/be_within.feature
vagrant-cloudstack-1.1.0 vendor/bundle/gems/rspec-expectations-2.14.5/features/built_in_matchers/be_within.feature
rspec-expectations-2.99.2 features/built_in_matchers/be_within.feature
dxruby_rp5-0.0.4 spec/vendor/rspec-expectations-2.14.4/features/built_in_matchers/be_within.feature
rspec-expectations-2.99.1 features/built_in_matchers/be_within.feature
rspec-expectations-2.99.0 features/built_in_matchers/be_within.feature
rspec-expectations-2.99.0.rc1 features/built_in_matchers/be_within.feature
rspec-expectations-2.99.0.beta2 features/built_in_matchers/be_within.feature
rspec-expectations-2.14.5 features/built_in_matchers/be_within.feature
mango-0.8.0 vendor/bundler/ruby/2.1.0/gems/rspec-expectations-2.14.4/features/built_in_matchers/be_within.feature
mango-0.7.1 vendor/bundler/ruby/2.0.0/gems/rspec-expectations-2.14.4/features/built_in_matchers/be_within.feature
dxruby_rp5-0.0.3 spec/vendor/rspec-expectations-2.14.4/features/built_in_matchers/be_within.feature
tuktuk-rails-0.0.10 vendor/bundle/ruby/2.0.0/gems/rspec-expectations-2.14.4/features/built_in_matchers/be_within.feature