Sha256: c7c4b18e77dce11de7b039fec38fc28d95687b037ed957378a444e8fbddef076

Contents?: true

Size: 1.61 KB

Versions: 1

Compression:

Stored size: 1.61 KB

Contents

# encoding: utf-8

# ==============================================================================
# Examples for testing nodes
# ==============================================================================

shared_context :node do

  def node
    attributes__ = defined?(attributes) ? attributes : {}
    block__      = defined?(block) ? block : nil
    described_class.new(attributes__, &block__)
  end

end # shared context

shared_examples :creating_immutable_node do

  include_context :node

  subject { node }

  it { is_expected.to be_kind_of AbstractMapper::Node }
  it { is_expected.to be_frozen, "expected #{subject.inspect} to be immutable" }

end # shared examples

shared_examples :creating_immutable_branch do

  include_context :node

  subject { node }

  it { is_expected.to be_kind_of AbstractMapper::Branch }
  it { is_expected.to be_frozen, "expected #{subject.inspect} to be immutable" }

end # shared examples

shared_examples :mapping_immutable_input do

  include_context :node

  let(:immutable_input) do
    begin
      input.dup.freeze
    rescue TypeError # in case input is a singleton that cannot be duplicated
      input
    end
  end

  subject(:transproc) { node.transproc }

  it "[creates a composable transproc]" do
    expect(transproc).to be_kind_of Transproc::Function
  end

  it "[maps the input]" do
    expect(transproc[immutable_input])
      .to eql(output), <<-REPORT.gsub(/.+\|/, "")
        |
        |#{node}
        |
        |Input: #{input}
        |
        |Output:
        |  expected: #{output}
        |       got: #{transproc[immutable_input]}
      REPORT
  end

end # shared examples

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
abstract_mapper-0.0.2 lib/rspec/nodes.rb