lib/synvert/snippets/rspec/collection_matcher.rb in synvert-0.0.11 vs lib/synvert/snippets/rspec/collection_matcher.rb in synvert-0.0.12
- old
+ new
@@ -1,15 +1,15 @@
Synvert::Rewriter.new "convert_rspec_collection_matcher", "RSpec converts collection matcher" do
if_gem 'rspec', {gte: '2.11.0'}
- {have: 'eq', have_exactly: 'eq', have_at_least: 'be >=', have_at_most: 'be <='}.each do |old_matcher, new_matcher|
- within_files 'spec/**/*_spec.rb' do
- # expect(collection).to have(3).items => expect(collection.size).to eq(3)
- # expect(collection).to have_exactly(3).items => expect(collection.size).to eq(3)
- # expect(collection).to have_at_least(3).items => expect(collection.size).to be >= 3
- # expect(collection).to have_at_most(3).items => expect(collection.size).to be <= 3
- #
- # expect(team).to have(3).players => expect(team.players.size).to eq 3
+ within_files 'spec/**/*_spec.rb' do
+ # expect(collection).to have(3).items => expect(collection.size).to eq(3)
+ # expect(collection).to have_exactly(3).items => expect(collection.size).to eq(3)
+ # expect(collection).to have_at_least(3).items => expect(collection.size).to be >= 3
+ # expect(collection).to have_at_most(3).items => expect(collection.size).to be <= 3
+ #
+ # expect(team).to have(3).players => expect(team.players.size).to eq 3
+ {have: 'eq', have_exactly: 'eq', have_at_least: 'be >=', have_at_most: 'be <='}.each do |old_matcher, new_matcher|
with_node type: 'send', message: 'to', arguments: {first: {type: 'send', receiver: {type: 'send', message: old_matcher}}} do
times = node.arguments.first.receiver.arguments.first.source(self)
items_name = node.arguments.first.message
if :items == items_name
replace_with "expect({{receiver.arguments}}.size).to #{new_matcher} #{times}"