Skip to content

Commit

Permalink
Decrease syntactic noise of argument lists.
Browse files Browse the repository at this point in the history
I find this:

foo(nil, :a => 1)

...to be much less noisy than this:

foo([nil, { :a => 1 }])

The first form more closely matches how people pass args
and kw args to methods, anyway.
  • Loading branch information
myronmarston committed Jan 29, 2014
1 parent 4a8a003 commit 3769d40
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions spec/rspec/mocks/method_signature_verifier_spec.rb
Expand Up @@ -10,15 +10,15 @@ def valid_non_kw_args?(arity)
described_class.new(test_method, [nil] * arity).valid?
end

def valid?(args)
def valid?(*args)
described_class.new(test_method, args).valid?
end

def description
described_class.new(test_method, []).error[/Expected (.*),/, 1]
end

def error_for(args)
def error_for(*args)
described_class.new(test_method, args).error
end

Expand All @@ -34,7 +34,7 @@ def arity_two(x, y); end
end

it 'does not treat a last-arg hash as kw args' do
expect(valid?([1, {}])).to eq(true)
expect(valid?(1, {})).to eq(true)
end

it 'is described precisely' do
Expand Down Expand Up @@ -96,21 +96,21 @@ def arity_kw(x, y:1, z:2); end
let(:test_method) { method(:arity_kw) }

it 'does not require any of the arguments' do
expect(valid?([nil])).to eq(true)
expect(valid?([nil, nil])).to eq(false)
expect(valid?(nil)).to eq(true)
expect(valid?(nil, nil)).to eq(false)
end

it 'does not allow an invalid keyword arguments' do
expect(valid?([nil, {:a => 1}])).to eq(false)
expect(valid?(nil, :a => 1)).to eq(false)
end

it 'is described precisely' do
expect(error_for([nil, {:a => 0, :b => 1}])).to \
expect(error_for(nil, :a => 0, :b => 1)).to \
eq("Invalid keyword arguments provided: a, b")
end

it 'is described precisely when arity is wrong' do
expect(error_for([])).to \
expect(error_for()).to \
eq("Wrong number of arguments. Expected 1, got 0.")
end
end
Expand All @@ -125,19 +125,19 @@ def arity_required_kw(x, y:, z:, a: 'default'); end
let(:test_method) { method(:arity_required_kw) }

it 'returns false unless all required keywords args are present' do
expect(valid?([nil, {:a => 0, :y => 1, :z => 2}])).to eq(true)
expect(valid?([nil, {:a => 0, :y => 1}])).to eq(false)
expect(valid?([nil, nil, {:a => 0, :y => 1, :z => 2}])).to eq(false)
expect(valid?([nil, nil])).to eq(false)
expect(valid?(nil, :a => 0, :y => 1, :z => 2)).to eq(true)
expect(valid?(nil, :a => 0, :y => 1)).to eq(false)
expect(valid?(nil, nil, :a => 0, :y => 1, :z => 2)).to eq(false)
expect(valid?(nil, nil)).to eq(false)
end

it 'is described precisely' do
expect(error_for([nil, {:a => 0}])).to \
expect(error_for(nil, :a => 0)).to \
eq("Missing required keyword arguments: y, z")
end

it 'is described precisely when arity is wrong' do
expect(error_for([{:z => 0, :y => 1}])).to \
expect(error_for(:z => 0, :y => 1)).to \
eq("Wrong number of arguments. Expected 1, got 0.")
end
end
Expand All @@ -150,15 +150,15 @@ def arity_required_kw_splat(w, *x, y:, z:, a: 'default'); end
let(:test_method) { method(:arity_required_kw_splat) }

it 'returns false unless all required keywords args are present' do
expect(valid?([nil, {:a => 0, :y => 1, :z => 2}])).to eq(true)
expect(valid?([nil, {:a => 0, :y => 1}])).to eq(false)
expect(valid?([nil, nil, {:a => 0, :y => 1, :z => 2}])).to eq(true)
expect(valid?([nil, nil, nil])).to eq(false)
expect(valid?([])).to eq(false)
expect(valid?(nil, :a => 0, :y => 1, :z => 2)).to eq(true)
expect(valid?(nil, :a => 0, :y => 1)).to eq(false)
expect(valid?(nil, nil, :a => 0, :y => 1, :z => 2)).to eq(true)
expect(valid?(nil, nil, nil)).to eq(false)
expect(valid?).to eq(false)
end

it 'is described precisely' do
expect(error_for([nil, {:y => 1}])).to \
expect(error_for(nil, :y => 1)).to \
eq("Missing required keyword arguments: z")
end
end
Expand Down

0 comments on commit 3769d40

Please sign in to comment.