Class: Synvert::FactoryGirl::SyntaxMethodsConverter

Inherits:
BaseConverter
  • Object
show all
Defined in:
lib/synvert/factory_girl/syntax_methods_converter.rb

Instance Attribute Summary

Attributes inherited from BaseConverter

#filename

Instance Method Summary collapse

Methods inherited from BaseConverter

#append_after, #append_to, #indent, #rewrite

Methods included from SexpHelper

#body, #contains_statement?, #message, #name, #receiver, #to_ast

Instance Method Details

#interesting_files ⇒ Object



6
7
8
9
10
# File 'lib/synvert/factory_girl/syntax_methods_converter.rb', line 6

def interesting_files
  [/spec\/spec_helper\.rb/, /spec\/support\/.*\.rb/, /spec\/.*_spec\.rb/] +
    [/test\/test_helper\.rb/, /test\/support\/.*\.rb/, /test\/.*_test\.rb/] +
    [/features\/support\/env\.rb/, /features\/.*\.rb/]
end

#on_block(node) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/synvert/factory_girl/syntax_methods_converter.rb', line 21

def on_block(node)
  if receiver(node) == to_ast("RSpec") &&
     message(node) == :configure &&
     !contains_statement?(body(node), "config.include FactoryGirl::Syntax::Methods")
    append_to node, "config.include FactoryGirl::Syntax::Methods"
  end

  super
end

#on_class(node) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/synvert/factory_girl/syntax_methods_converter.rb', line 12

def on_class(node)
  if (name(node) == to_ast("ActiveSupport::TestCase") || name(node) == to_ast("Test::Unit::TestCase")) &&
     !contains_statement?(body(node), "include FactoryGirl::Syntax::Methods")
    append_to node, "include FactoryGirl::Syntax::Methods"
  end

  super
end

#on_program(node) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/synvert/factory_girl/syntax_methods_converter.rb', line 40

def on_program(node)
  if filename == "features/support/env.rb" && !contains_statement?(node, "World(FactoryGirl::Syntax::Methods)")
    append_after node.children[0], "World(FactoryGirl::Syntax::Methods)"
  end

  node.updated(nil, process_all(node))
end

#on_send(node) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/synvert/factory_girl/syntax_methods_converter.rb', line 31

def on_send(node)
  if receiver(node) == to_ast("FactoryGirl") &&
     [:create, :build, :attributes_for, :build_stubbed, :create_list, :build_list, :create_pair, :build_pair].include?(message(node))
    replace node.loc.expression.resize("FactoryGirl.".size), ''
  end

  super
end