Sha256: 0dcc7ef7e5817cd217dff9cb8c9d2a522d9bca6e1ea0c49f5248d561b4717ce8

Contents?: true

Size: 1.61 KB

Versions: 3

Compression:

Stored size: 1.61 KB

Contents

# encoding: utf-8

# ==============================================================================
# Examples for testing transproc functions
# ==============================================================================

shared_context :call_transproc do
  let!(:__fn__) { described_class[*arguments] }
  let!(:__initial__) do
    begin
      input.dup
    rescue
      input
    end
  end

  subject { __fn__[input] }
end

shared_examples :transforming_data do
  include_context :call_transproc

  it '[returns the expected output]' do
    expect(subject).to eql(output), <<-REPORT.gsub(%r{.+\|}, '')
      |
      |fn = #{described_class}#{Array[*arguments]}
      |
      |fn[#{input}]
      |
      |  expected: #{output}
      |       got: #{subject}
    REPORT
  end
end

shared_examples :transforming_immutable_data do
  include_context :call_transproc

  it_behaves_like :transforming_data

  it '[keeps input unchanged]' do
    expect { subject }
      .not_to change { input }, <<-REPORT.gsub(%r{.+\|}, '')
        |
        |fn = #{described_class}#{Array[*arguments]}
        |
        |expected: not to change #{__initial__}
        |     got: changed it to #{input}
      REPORT
  end
end

shared_examples :mutating_input_data do
  include_context :call_transproc

  it_behaves_like :transforming_data

  it '[changes input]' do
    expect { subject }
      .to change { input }
      .to(output), <<-REPORT.gsub(%r{.+\|}, '')
        |
        |fn = #{described_class}#{Array[*arguments]}
        |
        |fn[#{input}]
        |
        |expected: to change input to #{output}
        |     got: #{input}
      REPORT
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
transproc-0.4.2 lib/transproc/rspec.rb
transproc-0.4.1 lib/transproc/rspec.rb
transproc-0.4.0 lib/transproc/rspec.rb