summaryrefslogtreecommitdiff
path: root/spec/ruby/core/data/with_spec.rb
blob: 9cd2d5733526ba7d9daae128c0980af16a597c61 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
require_relative '../../spec_helper'
require_relative 'fixtures/classes'

describe "Data#with" do
  it "returns self if given no arguments" do
    data = DataSpecs::Measure.new(amount: 42, unit: "km")
    data = data.with.should.equal?(data)
  end

  it "accepts keyword arguments" do
    data = DataSpecs::Measure.new(amount: 42, unit: "km")
    data = data.with(amount: 4, unit: "m")

    data.amount.should == 4
    data.unit.should == "m"
  end

  it "accepts String keyword arguments" do
    data = DataSpecs::Measure.new(amount: 42, unit: "km")
    data = data.with("amount" => 4, "unit" => "m")

    data.amount.should == 4
    data.unit.should == "m"
  end

  it "raises ArgumentError if no keyword arguments are given" do
    data = DataSpecs::Measure.new(amount: 42, unit: "km")

    -> {
      data.with(4, "m")
    }.should raise_error(ArgumentError, "wrong number of arguments (given 2, expected 0)")
  end
end