spec/synvert/node_ext_spec.rb in synvert-0.0.9 vs spec/synvert/node_ext_spec.rb in synvert-0.0.10
- old
+ new
@@ -65,14 +65,24 @@
expect(node.caller).to eq parse('RSpec.configure')
end
end
describe '#body' do
- it 'gets for block node' do
+ it 'gets one line for block node' do
node = parse('RSpec.configure do |config|; include EmailSpec::Helpers; end')
- expect(node.body).to eq parse('include EmailSpec::Helpers')
+ expect(node.body).to eq [parse('include EmailSpec::Helpers')]
end
+
+ it 'gets multiple lines for block node' do
+ node = parse('RSpec.configure do |config|; include EmailSpec::Helpers; include EmailSpec::Matchers; end')
+ expect(node.body).to eq [parse('include EmailSpec::Helpers'), parse('include EmailSpec::Matchers')]
+ end
+
+ it 'gets for begin node' do
+ node = parse('foo; bar')
+ expect(node.body).to eq [parse('foo'), parse('bar')]
+ end
end
describe "#condition" do
it 'gets for if node' do
node = parse('if defined?(Bundler); end')
@@ -130,10 +140,17 @@
instance.current_source = source
node = parse(source)
expect(node).to be_match(instance, type: 'send', receiver: 'params', message: '[]', arguments: [:user])
end
+ it 'matches assign number' do
+ source = 'at_least(0)'
+ instance.current_source = source
+ node = parse(source)
+ expect(node).to be_match(instance, type: 'send', arguments: [0])
+ end
+
it 'matches arguments with string' do
source = 'params["user"]'
instance.current_source = source
node = parse(source)
expect(node).to be_match(instance, type: 'send', receiver: 'params', message: '[]', arguments: ['user'])
@@ -142,8 +159,15 @@
it 'matches arguments any' do
source = 'config.middleware.insert_after ActiveRecord::QueryCache, Lifo::Cache, page_cache: false'
instance.current_source = source
node = parse(source)
expect(node).to be_match(instance, type: 'send', arguments: {any: 'Lifo::Cache'})
+ end
+
+ it 'matches not' do
+ source = 'class Synvert; end'
+ instance.current_source = source
+ node = parse(source)
+ expect(node).not_to be_match(instance, type: 'class', name: {not: 'Synvert'})
end
end
end