rails_best_practices 1.9.1 → 1.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. data/.rvmrc +1 -1
  2. data/Gemfile +1 -1
  3. data/Gemfile.lock +10 -2
  4. data/README.md +33 -27
  5. data/lib/rails_best_practices/analyzer.rb +13 -13
  6. data/lib/rails_best_practices/core/check.rb +7 -6
  7. data/lib/rails_best_practices/core/checking_visitor.rb +1 -1
  8. data/lib/rails_best_practices/core/runner.rb +2 -3
  9. data/lib/rails_best_practices/core_ext/sexp.rb +18 -17
  10. data/lib/rails_best_practices/lexicals.rb +1 -0
  11. data/lib/rails_best_practices/lexicals/long_line_check.rb +31 -0
  12. data/lib/rails_best_practices/prepares/config_prepare.rb +1 -1
  13. data/lib/rails_best_practices/reviews.rb +2 -0
  14. data/lib/rails_best_practices/reviews/add_model_virtual_attribute_review.rb +2 -2
  15. data/lib/rails_best_practices/reviews/always_add_db_index_review.rb +1 -1
  16. data/lib/rails_best_practices/reviews/hash_syntax_review.rb +63 -0
  17. data/lib/rails_best_practices/reviews/keep_finders_on_their_own_model_review.rb +1 -1
  18. data/lib/rails_best_practices/reviews/move_code_into_model_review.rb +1 -1
  19. data/lib/rails_best_practices/reviews/move_finder_to_named_scope_review.rb +1 -1
  20. data/lib/rails_best_practices/reviews/move_model_logic_into_model_review.rb +1 -1
  21. data/lib/rails_best_practices/reviews/needless_deep_nesting_review.rb +1 -1
  22. data/lib/rails_best_practices/reviews/overuse_route_customizations_review.rb +1 -1
  23. data/lib/rails_best_practices/reviews/protect_mass_assignment_review.rb +15 -6
  24. data/lib/rails_best_practices/reviews/remove_unused_methods_in_models_review.rb +4 -2
  25. data/lib/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review.rb +8 -4
  26. data/lib/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review.rb +2 -1
  27. data/lib/rails_best_practices/reviews/restrict_auto_generated_routes_review.rb +52 -8
  28. data/lib/rails_best_practices/reviews/simplify_render_in_views_review.rb +14 -2
  29. data/lib/rails_best_practices/reviews/use_before_filter_review.rb +8 -3
  30. data/lib/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review.rb +2 -1
  31. data/lib/rails_best_practices/reviews/use_observer_review.rb +1 -1
  32. data/lib/rails_best_practices/reviews/use_parentheses_in_method_def_review.rb +33 -0
  33. data/lib/rails_best_practices/reviews/use_query_attribute_review.rb +16 -6
  34. data/lib/rails_best_practices/reviews/use_say_with_time_in_migrations_review.rb +9 -6
  35. data/lib/rails_best_practices/reviews/use_scope_access_review.rb +8 -3
  36. data/lib/rails_best_practices/version.rb +1 -1
  37. data/rails_best_practices.yml +28 -25
  38. data/rake_rubies.sh +1 -1
  39. data/spec/rails_best_practices/analyzer_spec.rb +1 -1
  40. data/spec/rails_best_practices/core/check_spec.rb +7 -7
  41. data/spec/rails_best_practices/core/checking_visitor_spec.rb +7 -7
  42. data/spec/rails_best_practices/core/error_spec.rb +12 -12
  43. data/spec/rails_best_practices/core_ext/sexp_spec.rb +103 -85
  44. data/spec/rails_best_practices/lexicals/long_line_check_spec.rb +47 -0
  45. data/spec/rails_best_practices/lexicals/remove_tab_check_spec.rb +1 -1
  46. data/spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb +1 -1
  47. data/spec/rails_best_practices/prepares/config_prepare_spec.rb +1 -1
  48. data/spec/rails_best_practices/prepares/controller_prepare_spec.rb +1 -1
  49. data/spec/rails_best_practices/prepares/helper_prepare_spec.rb +1 -1
  50. data/spec/rails_best_practices/prepares/mailer_prepare_spec.rb +1 -1
  51. data/spec/rails_best_practices/prepares/model_prepare_spec.rb +4 -4
  52. data/spec/rails_best_practices/prepares/route_prepare_spec.rb +54 -54
  53. data/spec/rails_best_practices/prepares/schema_prepare_spec.rb +6 -6
  54. data/spec/rails_best_practices/reviews/add_model_virtual_attribute_review_spec.rb +4 -4
  55. data/spec/rails_best_practices/reviews/always_add_db_index_review_spec.rb +46 -46
  56. data/spec/rails_best_practices/reviews/dry_bundler_in_capistrano_review_spec.rb +3 -3
  57. data/spec/rails_best_practices/reviews/hash_syntax_review_spec.rb +67 -0
  58. data/spec/rails_best_practices/reviews/isolate_seed_data_review_spec.rb +8 -8
  59. data/spec/rails_best_practices/reviews/keep_finders_on_their_own_model_review_spec.rb +9 -9
  60. data/spec/rails_best_practices/reviews/law_of_demeter_review_spec.rb +7 -7
  61. data/spec/rails_best_practices/reviews/move_code_into_controller_review_spec.rb +1 -1
  62. data/spec/rails_best_practices/reviews/move_code_into_helper_review_spec.rb +1 -1
  63. data/spec/rails_best_practices/reviews/move_code_into_model_review_spec.rb +1 -1
  64. data/spec/rails_best_practices/reviews/move_finder_to_named_scope_review_spec.rb +13 -13
  65. data/spec/rails_best_practices/reviews/move_model_logic_into_model_review_spec.rb +2 -2
  66. data/spec/rails_best_practices/reviews/needless_deep_nesting_review_spec.rb +3 -3
  67. data/spec/rails_best_practices/reviews/not_use_default_route_review_spec.rb +3 -3
  68. data/spec/rails_best_practices/reviews/not_use_times_ago_in_words_review_spec.rb +1 -1
  69. data/spec/rails_best_practices/reviews/overuse_route_customizations_review_spec.rb +26 -26
  70. data/spec/rails_best_practices/reviews/protect_mass_assignment_review_spec.rb +11 -2
  71. data/spec/rails_best_practices/reviews/remove_empty_helpers_review_spec.rb +1 -1
  72. data/spec/rails_best_practices/reviews/remove_unused_methods_in_controllers_review_spec.rb +8 -8
  73. data/spec/rails_best_practices/reviews/remove_unused_methods_in_helpers_review_spec.rb +2 -2
  74. data/spec/rails_best_practices/reviews/remove_unused_methods_in_models_review_spec.rb +25 -10
  75. data/spec/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review_spec.rb +3 -3
  76. data/spec/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review_spec.rb +1 -1
  77. data/spec/rails_best_practices/reviews/restrict_auto_generated_routes_review_spec.rb +28 -28
  78. data/spec/rails_best_practices/reviews/simplify_render_in_controllers_review_spec.rb +4 -4
  79. data/spec/rails_best_practices/reviews/simplify_render_in_views_review_spec.rb +15 -7
  80. data/spec/rails_best_practices/reviews/use_before_filter_review_spec.rb +3 -3
  81. data/spec/rails_best_practices/reviews/use_model_association_review_spec.rb +3 -3
  82. data/spec/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review_spec.rb +3 -3
  83. data/spec/rails_best_practices/reviews/use_observer_review_spec.rb +5 -5
  84. data/spec/rails_best_practices/reviews/use_parenthesis_in_method_def_spec.rb +41 -0
  85. data/spec/rails_best_practices/reviews/use_query_attribute_review_spec.rb +3 -3
  86. data/spec/rails_best_practices/reviews/use_say_with_time_in_migrations_review_spec.rb +8 -8
  87. data/spec/rails_best_practices/reviews/use_scope_access_review_spec.rb +9 -9
  88. data/spec/spec_helper.rb +1 -1
  89. metadata +36 -29
  90. data/.rspec.example +0 -2
  91. data/.rvmrc.example +0 -2
@@ -3,17 +3,19 @@ require 'rails_best_practices/reviews/review'
3
3
 
4
4
  module RailsBestPractices
5
5
  module Reviews
6
- # Review a migration file to make sure to use say or say_with_time for customized data changes to produce a more readable output.
6
+ # Review a migration file to make sure to use say or say_with_time for customized data changes
7
+ # to produce a more readable output.
7
8
  #
8
- # See the best practice detials here http://rails-bestpractices.com/posts/46-use-say-and-say_with_time-in-migrations-to-make-a-useful-migration-log.
9
+ # See the best practice detials here
10
+ # http://rails-bestpractices.com/posts/46-use-say-and-say_with_time-in-migrations-to-make-a-useful-migration-log.
9
11
  #
10
12
  # Implementation:
11
13
  #
12
14
  # Review process:
13
15
  # check class method define nodes (self.up or self.down).
14
16
  # if there is a method call in the class method definition,
15
- # and the message of method call is not say, say_with_time and default migration methods (such as add_column and create_table),
16
- # then the method call should be wrapped by say or say_with_time.
17
+ # and the message of method call is not say, say_with_time and default migration methods
18
+ # (such as add_column and create_table), then the method call should be wrapped by say or say_with_time.
17
19
  class UseSayWithTimeInMigrationsReview < Review
18
20
  interesting_nodes :defs
19
21
  interesting_files MIGRATION_FILES
@@ -24,14 +26,15 @@ module RailsBestPractices
24
26
  "http://rails-bestpractices.com/posts/46-use-say-and-say_with_time-in-migrations-to-make-a-useful-migration-log"
25
27
  end
26
28
 
27
- # check a class method define node to see if there are method calls that need to be wrapped by say or say_with_time.
29
+ # check a class method define node to see if there are method calls that need to be wrapped by say
30
+ # or say_with_time.
28
31
  #
29
32
  # it will check the first block node,
30
33
  # if any method call whose message is not default migration methods in the block node,
31
34
  # then such method call should be wrapped by say or say_with_time
32
35
  def start_defs(node)
33
36
  node.body.statements.each do |child_node|
34
- next if child_node.grep_nodes_count(:sexp_type => [:fcall, :command], :message => WITH_SAY_METHODS) > 0
37
+ next if child_node.grep_nodes_count(sexp_type: [:fcall, :command], message: WITH_SAY_METHODS) > 0
35
38
 
36
39
  subject_node = if :method_add_block == child_node.sexp_type
37
40
  child_node[1]
@@ -42,11 +42,16 @@ module RailsBestPractices
42
42
  # and there is a redirect_to method call in the block body,
43
43
  # then it should be replaced by using scope access.
44
44
  def current_user_redirect?(node)
45
- all_conditions = node.conditional_statement == node.conditional_statement.all_conditions ? [node.conditional_statement] : node.conditional_statement.all_conditions
45
+ all_conditions = if node.conditional_statement == node.conditional_statement.all_conditions
46
+ [node.conditional_statement]
47
+ else
48
+ node.conditional_statement.all_conditions
49
+ end
46
50
  results = all_conditions.map do |condition_node|
47
- ["==", "!="].include?(condition_node.message.to_s) && (current_user?(condition_node.argument) || current_user?(condition_node.subject))
51
+ ["==", "!="].include?(condition_node.message.to_s) &&
52
+ (current_user?(condition_node.argument) || current_user?(condition_node.subject))
48
53
  end
49
- results.any? { |result| result == true } && node.body.grep_node(:message => "redirect_to")
54
+ results.any? { |result| result == true } && node.body.grep_node(message: "redirect_to")
50
55
  end
51
56
 
52
57
  # check a call node to see if it uses current_user, or current_user.id.
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module RailsBestPractices
3
- VERSION = "1.9.1"
3
+ VERSION = "1.10.0"
4
4
  end
@@ -1,34 +1,37 @@
1
- MoveFinderToNamedScopeCheck: { }
2
- UseModelAssociationCheck: { }
3
- UseScopeAccessCheck: { }
4
1
  AddModelVirtualAttributeCheck: { }
5
- ReplaceComplexCreationWithFactoryMethodCheck: { attribute_assignment_count: 2 }
6
- MoveModelLogicIntoModelCheck: { use_count: 4 }
7
- OveruseRouteCustomizationsCheck: { customize_count: 3 }
8
- NeedlessDeepNestingCheck: { nested_count: 2 }
9
- NotUseDefaultRouteCheck: { }
2
+ AlwaysAddDbIndexCheck: { }
3
+ DryBundlerInCapistranoCheck: { }
4
+ HashSyntaxCheck: { only_symbol: false, only_string: false }
5
+ IsolateSeedDataCheck: { }
10
6
  KeepFindersOnTheirOwnModelCheck: { }
11
7
  LawOfDemeterCheck: { }
12
- UseObserverCheck: { }
13
- IsolateSeedDataCheck: { }
14
- AlwaysAddDbIndexCheck: { }
15
- UseBeforeFilterCheck: { customize_count: 2 }
8
+ LongLineCheck: { max_line_length: 80 }
16
9
  MoveCodeIntoControllerCheck: { }
17
- MoveCodeIntoModelCheck: { use_count: 2 }
18
10
  MoveCodeIntoHelperCheck: { array_count: 3 }
19
- ReplaceInstanceVariableWithLocalVariableCheck: { }
20
- DryBundlerInCapistranoCheck: { }
21
- UseSayWithTimeInMigrationsCheck: { }
22
- UseQueryAttributeCheck: { }
23
- RemoveTrailingWhitespaceCheck: { }
24
- UseMultipartAlternativeAsContentTypeOfEmailCheck: { }
25
- SimplifyRenderInViewsCheck: { }
26
- SimplifyRenderInControllersCheck: { }
11
+ MoveCodeIntoModelCheck: { use_count: 2 }
12
+ MoveFinderToNamedScopeCheck: { }
13
+ MoveModelLogicIntoModelCheck: { use_count: 4 }
14
+ NeedlessDeepNestingCheck: { nested_count: 2 }
15
+ NotUseDefaultRouteCheck: { }
16
+ NotUseTimeAgoInWordsCheck: { }
17
+ OveruseRouteCustomizationsCheck: { customize_count: 3 }
18
+ ProtectMassAssignmentCheck: { }
27
19
  RemoveEmptyHelpersCheck: { }
28
20
  RemoveTabCheck: { }
29
- RestrictAutoGeneratedRoutesCheck: { }
30
- RemoveUnusedMethodsInModelsCheck: { except_methods: [] }
21
+ RemoveTrailingWhitespaceCheck: { }
31
22
  RemoveUnusedMethodsInControllersCheck: { except_methods: [] }
32
23
  RemoveUnusedMethodsInHelpersCheck: { except_methods: [] }
33
- NotUseTimeAgoInWordsCheck: { }
34
- ProtectMassAssignmentCheck: { }
24
+ RemoveUnusedMethodsInModelsCheck: { except_methods: [] }
25
+ ReplaceComplexCreationWithFactoryMethodCheck: { attribute_assignment_count: 2 }
26
+ ReplaceInstanceVariableWithLocalVariableCheck: { }
27
+ RestrictAutoGeneratedRoutesCheck: { }
28
+ SimplifyRenderInControllersCheck: { }
29
+ SimplifyRenderInViewsCheck: { }
30
+ UseBeforeFilterCheck: { customize_count: 2 }
31
+ UseModelAssociationCheck: { }
32
+ UseMultipartAlternativeAsContentTypeOfEmailCheck: { }
33
+ UseParenthesesInMethodDefCheck: { }
34
+ UseObserverCheck: { }
35
+ UseQueryAttributeCheck: { }
36
+ UseSayWithTimeInMigrationsCheck: { }
37
+ UseScopeAccessCheck: { }
data/rake_rubies.sh CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/bin/bash
2
- rubies=( 1.9.2-p290 1.9.3-p125 )
2
+ rubies=( 1.9.2-p320 1.9.3-p194 )
3
3
  gemset="rails_best_practices"
4
4
 
5
5
  for x in ${rubies[*]}
@@ -29,7 +29,7 @@ module RailsBestPractices
29
29
  it "should output errors in terminal" do
30
30
  check1 = Reviews::LawOfDemeterReview.new
31
31
  check2 = Reviews::UseQueryAttributeReview.new
32
- runner = Core::Runner.new(:reviews => [check1, check2])
32
+ runner = Core::Runner.new(reviews: [check1, check2])
33
33
  check1.add_error "law of demeter", "app/models/user.rb", 10
34
34
  check2.add_error "use query attribute", "app/models/post.rb", 100
35
35
  subject.runner = runner
@@ -14,19 +14,19 @@ module RailsBestPractices::Core
14
14
 
15
15
  context "node_start" do
16
16
  it "should call start_if" do
17
- node = stub(:sexp_type => :if)
17
+ node = stub(sexp_type: :if)
18
18
  check.should_receive(:send).with("start_if", node)
19
19
  check.node_start(node)
20
20
  end
21
21
 
22
22
  it "should call start_call" do
23
- node = stub(:sexp_type => :call)
23
+ node = stub(sexp_type: :call)
24
24
  check.should_receive(:send).with("start_call", node)
25
25
  check.node_start(node)
26
26
  end
27
27
 
28
28
  it "should print node if debug mode" do
29
- node = stub(:sexp_type => :call)
29
+ node = stub(sexp_type: :call)
30
30
  Check.class_eval { debug }
31
31
  check.should_receive(:send).with("start_call", node)
32
32
  check.should_receive(:ap).with(node)
@@ -37,13 +37,13 @@ module RailsBestPractices::Core
37
37
 
38
38
  context "node_end" do
39
39
  it "should call end_if" do
40
- node = stub(:sexp_type => :if)
40
+ node = stub(sexp_type: :if)
41
41
  check.should_receive(:send).with("end_if", node)
42
42
  check.node_end(node)
43
43
  end
44
44
 
45
45
  it "should call end_call" do
46
- node = stub(:sexp_type => :call)
46
+ node = stub(sexp_type: :call)
47
47
  check.should_receive(:send).with("end_call", node)
48
48
  check.node_end(node)
49
49
  end
@@ -55,7 +55,7 @@ module RailsBestPractices::Core
55
55
  check.class.add_callback "start_call" do
56
56
  execute = true
57
57
  end
58
- node = stub(:sexp_type => :call)
58
+ node = stub(sexp_type: :call)
59
59
  check.node_start(node)
60
60
  execute.should be_true
61
61
  end
@@ -65,7 +65,7 @@ module RailsBestPractices::Core
65
65
  check.class.add_callback "end_call" do
66
66
  execute = true
67
67
  end
68
- node = stub(:sexp_type => :call)
68
+ node = stub(sexp_type: :call)
69
69
  check.node_end(node)
70
70
  execute.should be_true
71
71
  end
@@ -34,9 +34,9 @@ module RailsBestPractices::Core
34
34
  let(:review2) { TestReview2.new }
35
35
  let(:visitor) {
36
36
  CheckingVisitor.new(
37
- :lexicals => [lexical1, lexical2],
38
- :prepares => [prepare1, prepare2],
39
- :reviews => [review1, review2]
37
+ lexicals: [lexical1, lexical2],
38
+ prepares: [prepare1, prepare2],
39
+ reviews: [review1, review2]
40
40
  )
41
41
  }
42
42
 
@@ -49,28 +49,28 @@ module RailsBestPractices::Core
49
49
  end
50
50
 
51
51
  it "should prepare model associations" do
52
- node = stub(:sexp_type => :call, :children => [], :file => "app/models/user.rb")
52
+ node = stub(sexp_type: :call, children: [], file: "app/models/user.rb")
53
53
  prepare1.should_receive(:node_start).with(node)
54
54
  prepare1.should_receive(:node_end).with(node)
55
55
  visitor.prepare(node)
56
56
  end
57
57
 
58
58
  it "should prepare mailer names" do
59
- node = stub(:sexp_type => :class, :children => [], :file => "app/mailers/user_mailer.rb")
59
+ node = stub(sexp_type: :class, children: [], file: "app/mailers/user_mailer.rb")
60
60
  prepare2.should_receive(:node_start).with(node)
61
61
  prepare2.should_receive(:node_end).with(node)
62
62
  visitor.prepare(node)
63
63
  end
64
64
 
65
65
  it "should review controller method definitions" do
66
- node = stub(:sexp_type => :defn, :children => [], :file => "app/controllers/users_controller.rb")
66
+ node = stub(sexp_type: :defn, children: [], file: "app/controllers/users_controller.rb")
67
67
  review1.should_receive(:node_start).with(node)
68
68
  review1.should_receive(:node_end).with(node)
69
69
  visitor.review(node)
70
70
  end
71
71
 
72
72
  it "should review view calls" do
73
- node = stub(:sexp_type => :call, :children => [], :file => "app/views/users/new.html.erb")
73
+ node = stub(sexp_type: :call, children: [], file: "app/views/users/new.html.erb")
74
74
  review2.should_receive(:node_start).with(node)
75
75
  review2.should_receive(:node_end).with(node)
76
76
  visitor.review(node)
@@ -8,27 +8,27 @@ module RailsBestPractices::Core
8
8
 
9
9
  it "should return error with filename, line number and message" do
10
10
  Error.new(
11
- :filename => "app/models/user.rb",
12
- :line_number => "100",
13
- :message => "not good",
14
- :type => "BogusReview").to_s.should == "app/models/user.rb:100 - not good"
11
+ filename: "app/models/user.rb",
12
+ line_number: "100",
13
+ message: "not good",
14
+ type: "BogusReview").to_s.should == "app/models/user.rb:100 - not good"
15
15
  end
16
16
 
17
17
  it "should return short filename" do
18
18
  Runner.base_path = "../rails-bestpractices.com"
19
19
  Error.new(
20
- :filename => "../rails-bestpractices.com/app/models/user.rb",
21
- :line_number => "100",
22
- :message => "not good",
23
- :type => "BogusReview").short_filename.should == "app/models/user.rb"
20
+ filename: "../rails-bestpractices.com/app/models/user.rb",
21
+ line_number: "100",
22
+ message: "not good",
23
+ type: "BogusReview").short_filename.should == "app/models/user.rb"
24
24
  end
25
25
 
26
26
  it "should return first line number" do
27
27
  Error.new(
28
- :filename => "app/models/user.rb",
29
- :line_number => "50,70,100",
30
- :message => "not good",
31
- :type => "BogusReview").first_line_number.should == "50"
28
+ filename: "app/models/user.rb",
29
+ line_number: "50,70,100",
30
+ message: "not good",
31
+ type: "BogusReview").first_line_number.should == "50"
32
32
  end
33
33
  end
34
34
  end
@@ -9,29 +9,34 @@ describe Sexp do
9
9
  ActiveRecord::Base.connection
10
10
  end
11
11
  alias :test_new :test
12
+ CONST = { foo: :bar }
12
13
  end
13
14
  EOF
14
15
  @node = parse_content(content)
15
16
  end
16
17
 
17
18
  it "should return class line" do
18
- @node.grep_node(:sexp_type => :class).line.should == 1
19
+ @node.grep_node(sexp_type: :class).line.should == 1
19
20
  end
20
21
 
21
22
  it "should return def line" do
22
- @node.grep_node(:sexp_type => :def).line.should == 2
23
+ @node.grep_node(sexp_type: :def).line.should == 2
23
24
  end
24
25
 
25
26
  it "should return const line" do
26
- @node.grep_node(:sexp_type => :const_ref).line.should == 1
27
+ @node.grep_node(sexp_type: :const_ref).line.should == 1
27
28
  end
28
29
 
29
30
  it "should return const path line" do
30
- @node.grep_node(:sexp_type => :const_path_ref).line.should == 3
31
+ @node.grep_node(sexp_type: :const_path_ref).line.should == 3
31
32
  end
32
33
 
33
34
  it "should return alias line" do
34
- @node.grep_node(:sexp_type => :alias).line.should == 5
35
+ @node.grep_node(sexp_type: :alias).line.should == 5
36
+ end
37
+
38
+ it "should return hash line" do
39
+ @node.grep_node(sexp_type: :hash).line.should == 6
35
40
  end
36
41
  end
37
42
 
@@ -47,7 +52,7 @@ describe Sexp do
47
52
 
48
53
  it "should get the call nodes with subject current_user" do
49
54
  nodes = []
50
- @node.grep_nodes(:sexp_type => :call, :subject => "current_user") { |node| nodes << node }
55
+ @node.grep_nodes(sexp_type: :call, subject: "current_user") { |node| nodes << node }
51
56
  if RUBY_VERSION == "1.9.2"
52
57
  nodes.should == [s(:call, s(:var_ref, s(:@ident, "current_user", s(2, 8))), :".", s(:@ident, "posts", s(2, 21)))]
53
58
  else
@@ -57,7 +62,7 @@ describe Sexp do
57
62
 
58
63
  it "should get the call nodes with different messages" do
59
64
  nodes = []
60
- @node.grep_nodes(:sexp_type => :call, :message => ["posts", "find"]) { |node| nodes << node }
65
+ @node.grep_nodes(sexp_type: :call, message: ["posts", "find"]) { |node| nodes << node }
61
66
  if RUBY_VERSION == "1.9.2"
62
67
  nodes.should == [s(:call, s(:call, s(:var_ref, s(:@ident, "current_user", s(2, 8))), :".", s(:@ident, "posts", s(2, 21))), :".", s(:@ident, "find", s(2, 27))), s(:call, s(:var_ref, s(:@ident, "current_user", s(2, 8))), :".", s(:@ident, "posts", s(2, 21)))]
63
68
  else
@@ -68,13 +73,13 @@ describe Sexp do
68
73
  if RUBY_VERSION == "1.9.2"
69
74
  it "should get the var_ref node with to_s" do
70
75
  nodes = []
71
- @node.grep_nodes(:sexp_type => :var_ref, :to_s => "current_user") { |node| nodes << node }
76
+ @node.grep_nodes(sexp_type: :var_ref, to_s: "current_user") { |node| nodes << node }
72
77
  nodes.should == [s(:var_ref, s(:@ident, "current_user", s(2, 8)))]
73
78
  end
74
79
  else
75
80
  it "should get the vcall node with to_s" do
76
81
  nodes = []
77
- @node.grep_nodes(:sexp_type => :vcall, :to_s => "current_user") { |node| nodes << node }
82
+ @node.grep_nodes(sexp_type: :vcall, to_s: "current_user") { |node| nodes << node }
78
83
  nodes.should == [s(:vcall, s(:@ident, "current_user", s(2, 8)))]
79
84
  end
80
85
  end
@@ -91,7 +96,7 @@ describe Sexp do
91
96
  end
92
97
 
93
98
  it "should get first node with empty argument" do
94
- node = @node.grep_node(:sexp_type => :call, :subject => "current_user")
99
+ node = @node.grep_node(sexp_type: :call, subject: "current_user")
95
100
  if RUBY_VERSION == "1.9.2"
96
101
  node.should == s(:call, s(:var_ref, s(:@ident, "current_user", s(2, 8))), :".", s(:@ident, "posts", s(2, 21)))
97
102
  else
@@ -111,13 +116,13 @@ describe Sexp do
111
116
  end
112
117
 
113
118
  it "should get the count of call nodes" do
114
- @node.grep_nodes_count(:sexp_type => :call).should == 2
119
+ @node.grep_nodes_count(sexp_type: :call).should == 2
115
120
  end
116
121
  end
117
122
 
118
123
  describe "subject" do
119
124
  it "should get subject of assign node" do
120
- node = parse_content("user.name = params[:name]").grep_node(:sexp_type => :assign)
125
+ node = parse_content("user.name = params[:name]").grep_node(sexp_type: :assign)
121
126
  subject = node.subject
122
127
  subject.sexp_type.should == :field
123
128
  subject.subject.to_s.should == "user"
@@ -125,17 +130,17 @@ describe Sexp do
125
130
  end
126
131
 
127
132
  it "should get subject of field node" do
128
- node = parse_content("user.name = params[:name]").grep_node(:sexp_type => :field)
133
+ node = parse_content("user.name = params[:name]").grep_node(sexp_type: :field)
129
134
  node.subject.to_s.should == "user"
130
135
  end
131
136
 
132
137
  it "should get subject of call node" do
133
- node = parse_content("user.name").grep_node(:sexp_type => :call)
138
+ node = parse_content("user.name").grep_node(sexp_type: :call)
134
139
  node.subject.to_s.should == "user"
135
140
  end
136
141
 
137
142
  it "should get subject of binary" do
138
- node = parse_content("user == 'user_name'").grep_node(:sexp_type => :binary)
143
+ node = parse_content("user == 'user_name'").grep_node(sexp_type: :binary)
139
144
  node.subject.to_s.should == "user"
140
145
  end
141
146
 
@@ -144,152 +149,152 @@ describe Sexp do
144
149
  map.resources :posts do
145
150
  end
146
151
  EOF
147
- node = parse_content(content).grep_node(:sexp_type => :command_call)
152
+ node = parse_content(content).grep_node(sexp_type: :command_call)
148
153
  node.subject.to_s.should == "map"
149
154
  end
150
155
 
151
156
  it "should get subject of method_add_arg" do
152
- node = parse_content("Post.find(:all)").grep_node(:sexp_type => :method_add_arg)
157
+ node = parse_content("Post.find(:all)").grep_node(sexp_type: :method_add_arg)
153
158
  node.subject.to_s.should == "Post"
154
159
  end
155
160
 
156
161
  it "should get subject of method_add_block" do
157
- node = parse_content("Post.save do; end").grep_node(:sexp_type => :method_add_block)
162
+ node = parse_content("Post.save do; end").grep_node(sexp_type: :method_add_block)
158
163
  node.subject.to_s.should == "Post"
159
164
  end
160
165
  end
161
166
 
162
167
  describe "module_name" do
163
168
  it "should get module name of module node" do
164
- node = parse_content("module Admin; end").grep_node(:sexp_type => :module)
169
+ node = parse_content("module Admin; end").grep_node(sexp_type: :module)
165
170
  node.module_name.to_s.should == "Admin"
166
171
  end
167
172
  end
168
173
 
169
174
  describe "class_name" do
170
175
  it "should get class name of class node" do
171
- node = parse_content("class User; end").grep_node(:sexp_type => :class)
176
+ node = parse_content("class User; end").grep_node(sexp_type: :class)
172
177
  node.class_name.to_s.should == "User"
173
178
  end
174
179
  end
175
180
 
176
181
  describe "base_class" do
177
182
  it "should get base class of class node" do
178
- node = parse_content("class User < ActiveRecord::Base; end").grep_node(:sexp_type => :class)
183
+ node = parse_content("class User < ActiveRecord::Base; end").grep_node(sexp_type: :class)
179
184
  node.base_class.to_s.should == "ActiveRecord::Base"
180
185
  end
181
186
  end
182
187
 
183
188
  describe "left_value" do
184
189
  it "should get the left value of assign" do
185
- node = parse_content("user = current_user").grep_node(:sexp_type => :assign)
190
+ node = parse_content("user = current_user").grep_node(sexp_type: :assign)
186
191
  node.left_value.to_s.should == "user"
187
192
  end
188
193
  end
189
194
 
190
195
  describe "right_value" do
191
196
  it "should get the right value of assign" do
192
- node = parse_content("user = current_user").grep_node(:sexp_type => :assign)
197
+ node = parse_content("user = current_user").grep_node(sexp_type: :assign)
193
198
  node.right_value.to_s.should == "current_user"
194
199
  end
195
200
  end
196
201
 
197
202
  describe "message" do
198
203
  it "should get the message of command" do
199
- node = parse_content("has_many :projects").grep_node(:sexp_type => :command)
204
+ node = parse_content("has_many :projects").grep_node(sexp_type: :command)
200
205
  node.message.to_s.should == "has_many"
201
206
  end
202
207
 
203
208
  it "should get the message of command_call" do
204
- node = parse_content("map.resources :posts do; end").grep_node(:sexp_type => :command_call)
209
+ node = parse_content("map.resources :posts do; end").grep_node(sexp_type: :command_call)
205
210
  node.message.to_s.should == "resources"
206
211
  end
207
212
 
208
213
  it "should get the message of field" do
209
- node = parse_content("user.name = 'test'").grep_node(:sexp_type => :field)
214
+ node = parse_content("user.name = 'test'").grep_node(sexp_type: :field)
210
215
  node.message.to_s.should == "name"
211
216
  end
212
217
 
213
218
  it "should get the message of call" do
214
- node = parse_content("user.name").grep_node(:sexp_type => :call)
219
+ node = parse_content("user.name").grep_node(sexp_type: :call)
215
220
  node.message.to_s.should == "name"
216
221
  end
217
222
 
218
223
  it "should get the message of binary" do
219
- node = parse_content("user.name == 'test'").grep_node(:sexp_type => :binary)
224
+ node = parse_content("user.name == 'test'").grep_node(sexp_type: :binary)
220
225
  node.message.to_s.should == "=="
221
226
  end
222
227
 
223
228
  it "should get the message of fcall" do
224
- node = parse_content("test?('world')").grep_node(:sexp_type => :fcall)
229
+ node = parse_content("test?('world')").grep_node(sexp_type: :fcall)
225
230
  node.message.to_s.should == "test?"
226
231
  end
227
232
 
228
233
  it "should get the message of method_add_arg" do
229
- node = parse_content("Post.find(:all)").grep_node(:sexp_type => :method_add_arg)
234
+ node = parse_content("Post.find(:all)").grep_node(sexp_type: :method_add_arg)
230
235
  node.message.to_s.should == "find"
231
236
  end
232
237
 
233
238
  it "should get the message of method_add_block" do
234
- node = parse_content("Post.save do; end").grep_node(:sexp_type => :method_add_block)
239
+ node = parse_content("Post.save do; end").grep_node(sexp_type: :method_add_block)
235
240
  node.message.to_s.should == "save"
236
241
  end
237
242
  end
238
243
 
239
244
  describe "arguments" do
240
245
  it "should get the arguments of command" do
241
- node = parse_content("resources :posts do; end").grep_node(:sexp_type => :command)
246
+ node = parse_content("resources :posts do; end").grep_node(sexp_type: :command)
242
247
  node.arguments.sexp_type.should == :args_add_block
243
248
  end
244
249
 
245
250
  it "should get the arguments of command_call" do
246
- node = parse_content("map.resources :posts do; end").grep_node(:sexp_type => :command_call)
251
+ node = parse_content("map.resources :posts do; end").grep_node(sexp_type: :command_call)
247
252
  node.arguments.sexp_type.should == :args_add_block
248
253
  end
249
254
 
250
255
  it "should get the arguments of method_add_arg" do
251
- node = parse_content("User.find(:all)").grep_node(:sexp_type => :method_add_arg)
256
+ node = parse_content("User.find(:all)").grep_node(sexp_type: :method_add_arg)
252
257
  node.arguments.sexp_type.should == :args_add_block
253
258
  end
254
259
 
255
260
  it "should get the arguments of method_add_block" do
256
- node = parse_content("Post.save(false) do; end").grep_node(:sexp_type => :method_add_block)
261
+ node = parse_content("Post.save(false) do; end").grep_node(sexp_type: :method_add_block)
257
262
  node.arguments.sexp_type.should == :args_add_block
258
263
  end
259
264
  end
260
265
 
261
266
  describe "argument" do
262
267
  it "should get the argument of binary" do
263
- node = parse_content("user == current_user").grep_node(:sexp_type => :binary)
268
+ node = parse_content("user == current_user").grep_node(sexp_type: :binary)
264
269
  node.argument.to_s.should == "current_user"
265
270
  end
266
271
  end
267
272
 
268
273
  describe "all" do
269
274
  it "should get all arguments" do
270
- node = parse_content("puts 'hello', 'world'").grep_node(:sexp_type => :args_add_block)
275
+ node = parse_content("puts 'hello', 'world'").grep_node(sexp_type: :args_add_block)
271
276
  node.all.map(&:to_s).should == ["hello", "world"]
272
277
  end
273
278
 
274
279
  it "should get all arguments with &:" do
275
- node = parse_content("user.posts.map(&:title)").grep_node(:sexp_type => :args_add_block)
280
+ node = parse_content("user.posts.map(&:title)").grep_node(sexp_type: :args_add_block)
276
281
  node.all.map(&:to_s).should == ["title"]
277
282
  end
278
283
 
279
284
  it "no error for args_add_star" do
280
- node = parse_content("send(:\"\#{route}_url\", *args)").grep_node(:sexp_type => :args_add_block)
285
+ node = parse_content("send(:\"\#{route}_url\", *args)").grep_node(sexp_type: :args_add_block)
281
286
  lambda { node.all }.should_not raise_error
282
287
  end
283
288
  end
284
289
 
285
290
  describe "conditional_statement" do
286
291
  it "should get conditional statement of if" do
287
- node = parse_content("if true; end").grep_node(:sexp_type => :if)
292
+ node = parse_content("if true; end").grep_node(sexp_type: :if)
288
293
  node.conditional_statement.to_s.should == "true"
289
294
  end
290
295
 
291
296
  it "should get conditional statement of unless" do
292
- node = parse_content("unless true; end").grep_node(:sexp_type => :unless)
297
+ node = parse_content("unless true; end").grep_node(sexp_type: :unless)
293
298
  node.conditional_statement.to_s.should == "true"
294
299
  end
295
300
 
@@ -299,100 +304,108 @@ describe Sexp do
299
304
  elsif false
300
305
  end
301
306
  EOF
302
- node = parse_content(content).grep_node(:sexp_type => :elsif)
307
+ node = parse_content(content).grep_node(sexp_type: :elsif)
303
308
  node.conditional_statement.to_s.should == "false"
304
309
  end
310
+
311
+ it "should get conditional statement of ifop" do
312
+ content =<<-EOF
313
+ user ? user.name : nil
314
+ EOF
315
+ node = parse_content(content).grep_node(sexp_type: :ifop)
316
+ node.conditional_statement.to_s.should == "user"
317
+ end
305
318
  end
306
319
 
307
320
  describe "all_conditions" do
308
321
  it "should get all conditions" do
309
- node = parse_content("user == current_user && user.valid? || user.admin?").grep_node(:sexp_type => :binary)
322
+ node = parse_content("user == current_user && user.valid? || user.admin?").grep_node(sexp_type: :binary)
310
323
  node.all_conditions.size.should == 3
311
324
  end
312
325
  end
313
326
 
314
327
  describe "method_name" do
315
328
  it "should get the method name of def" do
316
- node = parse_content("def show; end").grep_node(:sexp_type => :def)
329
+ node = parse_content("def show; end").grep_node(sexp_type: :def)
317
330
  node.method_name.to_s.should == "show"
318
331
  end
319
332
 
320
333
  it "should get the method name of defs" do
321
- node = parse_content("def self.find; end").grep_node(:sexp_type => :defs)
334
+ node = parse_content("def self.find; end").grep_node(sexp_type: :defs)
322
335
  node.method_name.to_s.should == "find"
323
336
  end
324
337
  end
325
338
 
326
339
  describe "body" do
327
340
  it "should get body of class" do
328
- node = parse_content("class User; end").grep_node(:sexp_type => :class)
341
+ node = parse_content("class User; end").grep_node(sexp_type: :class)
329
342
  node.body.sexp_type.should == :bodystmt
330
343
  end
331
344
 
332
345
  it "should get body of def" do
333
- node = parse_content("def login; end").grep_node(:sexp_type => :def)
346
+ node = parse_content("def login; end").grep_node(sexp_type: :def)
334
347
  node.body.sexp_type.should == :bodystmt
335
348
  end
336
349
 
337
350
  it "should get body of defs" do
338
- node = parse_content("def self.login; end").grep_node(:sexp_type => :defs)
351
+ node = parse_content("def self.login; end").grep_node(sexp_type: :defs)
339
352
  node.body.sexp_type.should == :bodystmt
340
353
  end
341
354
 
342
355
  it "should get body of module" do
343
- node = parse_content("module Enumerable; end").grep_node(:sexp_type => :module)
356
+ node = parse_content("module Enumerable; end").grep_node(sexp_type: :module)
344
357
  node.body.sexp_type.should == :bodystmt
345
358
  end
346
359
 
347
360
  it "should get body of if" do
348
- node = parse_content("if true; puts 'hello world'; end").grep_node(:sexp_type => :if)
361
+ node = parse_content("if true; puts 'hello world'; end").grep_node(sexp_type: :if)
349
362
  node.body.sexp_type.should == :stmts_add
350
363
  end
351
364
 
352
365
  it "should get body of elsif" do
353
- node = parse_content("if true; elsif true; puts 'hello world'; end").grep_node(:sexp_type => :elsif)
366
+ node = parse_content("if true; elsif true; puts 'hello world'; end").grep_node(sexp_type: :elsif)
354
367
  node.body.sexp_type.should == :stmts_add
355
368
  end
356
369
 
357
370
  it "should get body of unless" do
358
- node = parse_content("unless true; puts 'hello world'; end").grep_node(:sexp_type => :unless)
371
+ node = parse_content("unless true; puts 'hello world'; end").grep_node(sexp_type: :unless)
359
372
  node.body.sexp_type.should == :stmts_add
360
373
  end
361
374
 
362
375
  it "should get body of else" do
363
- node = parse_content("if true; else; puts 'hello world'; end").grep_node(:sexp_type => :else)
376
+ node = parse_content("if true; else; puts 'hello world'; end").grep_node(sexp_type: :else)
364
377
  node.body.sexp_type.should == :stmts_add
365
378
  end
366
379
  end
367
380
 
368
381
  describe "block" do
369
382
  it "sould get block of method_add_block node" do
370
- node = parse_content("resources :posts do; resources :comments; end").grep_node(:sexp_type => :method_add_block)
383
+ node = parse_content("resources :posts do; resources :comments; end").grep_node(sexp_type: :method_add_block)
371
384
  node.block.sexp_type.should == :do_block
372
385
  end
373
386
  end
374
387
 
375
388
  describe "statements" do
376
389
  it "should get statements of do_block node" do
377
- node = parse_content("resources :posts do; resources :comments; resources :like; end").grep_node(:sexp_type => :do_block)
390
+ node = parse_content("resources :posts do; resources :comments; resources :like; end").grep_node(sexp_type: :do_block)
378
391
  node.statements.size.should == 2
379
392
  end
380
393
 
381
394
  it "should get statements of bodystmt node" do
382
- node = parse_content("class User; def login?; end; def admin?; end; end").grep_node(:sexp_type => :bodystmt)
395
+ node = parse_content("class User; def login?; end; def admin?; end; end").grep_node(sexp_type: :bodystmt)
383
396
  node.statements.size.should == 2
384
397
  end
385
398
  end
386
399
 
387
400
  describe "hash_value" do
388
401
  it "should get value for hash node" do
389
- node = parse_content("{first_name: 'Richard', last_name: 'Huang'}").grep_node(:sexp_type => :hash)
402
+ node = parse_content("{first_name: 'Richard', last_name: 'Huang'}").grep_node(sexp_type: :hash)
390
403
  node.hash_value("first_name").to_s.should == "Richard"
391
404
  node.hash_value("last_name").to_s.should == "Huang"
392
405
  end
393
406
 
394
407
  it "should get value for bare_assoc_hash" do
395
- node = parse_content("add_user :user, first_name: 'Richard', last_name: 'Huang'").grep_node(:sexp_type => :bare_assoc_hash)
408
+ node = parse_content("add_user :user, first_name: 'Richard', last_name: 'Huang'").grep_node(sexp_type: :bare_assoc_hash)
396
409
  node.hash_value("first_name").to_s.should == "Richard"
397
410
  node.hash_value("last_name").to_s.should == "Huang"
398
411
  end
@@ -400,65 +413,65 @@ describe Sexp do
400
413
 
401
414
  describe "hash_size" do
402
415
  it "should get value for hash node" do
403
- node = parse_content("{first_name: 'Richard', last_name: 'Huang'}").grep_node(:sexp_type => :hash)
416
+ node = parse_content("{first_name: 'Richard', last_name: 'Huang'}").grep_node(sexp_type: :hash)
404
417
  node.hash_size.should == 2
405
418
  end
406
419
 
407
420
  it "should get value for bare_assoc_hash" do
408
- node = parse_content("add_user :user, first_name: 'Richard', last_name: 'Huang'").grep_node(:sexp_type => :bare_assoc_hash)
421
+ node = parse_content("add_user :user, first_name: 'Richard', last_name: 'Huang'").grep_node(sexp_type: :bare_assoc_hash)
409
422
  node.hash_size.should == 2
410
423
  end
411
424
  end
412
425
 
413
426
  describe "hash_keys" do
414
427
  it "should get hash_keys for hash node" do
415
- node = parse_content("{first_name: 'Richard', last_name: 'Huang'}").grep_node(:sexp_type => :hash)
428
+ node = parse_content("{first_name: 'Richard', last_name: 'Huang'}").grep_node(sexp_type: :hash)
416
429
  node.hash_keys.should == ["first_name", "last_name"]
417
430
  end
418
431
 
419
432
  it "should get hash_keys for bare_assoc_hash" do
420
- node = parse_content("add_user :user, first_name: 'Richard', last_name: 'Huang'").grep_node(:sexp_type => :bare_assoc_hash)
433
+ node = parse_content("add_user :user, first_name: 'Richard', last_name: 'Huang'").grep_node(sexp_type: :bare_assoc_hash)
421
434
  node.hash_keys.should == ["first_name", "last_name"]
422
435
  end
423
436
  end
424
437
 
425
438
  describe "hash_values" do
426
439
  it "should get hash_values for hash node" do
427
- node = parse_content("{first_name: 'Richard', last_name: 'Huang'}").grep_node(:sexp_type => :hash)
440
+ node = parse_content("{first_name: 'Richard', last_name: 'Huang'}").grep_node(sexp_type: :hash)
428
441
  node.hash_values.map(&:to_s).should == ["Richard", "Huang"]
429
442
  end
430
443
 
431
444
  it "should get hash_values for bare_assoc_hash" do
432
- node = parse_content("add_user :user, first_name: 'Richard', last_name: 'Huang'").grep_node(:sexp_type => :bare_assoc_hash)
445
+ node = parse_content("add_user :user, first_name: 'Richard', last_name: 'Huang'").grep_node(sexp_type: :bare_assoc_hash)
433
446
  node.hash_values.map(&:to_s).should == ["Richard", "Huang"]
434
447
  end
435
448
  end
436
449
 
437
450
  describe "array_size" do
438
451
  it "should get array size" do
439
- node = parse_content("['first_name', 'last_name']").grep_node(:sexp_type => :array)
452
+ node = parse_content("['first_name', 'last_name']").grep_node(sexp_type: :array)
440
453
  node.array_size.should == 2
441
454
  end
442
455
 
443
456
  it "should get 0" do
444
- node = parse_content("[]").grep_node(:sexp_type => :array)
457
+ node = parse_content("[]").grep_node(sexp_type: :array)
445
458
  node.array_size.should == 0
446
459
  end
447
460
  end
448
461
 
449
462
  describe "array_values" do
450
463
  it "should get array values" do
451
- node = parse_content("['first_name', 'last_name']").grep_node(:sexp_type => :array)
464
+ node = parse_content("['first_name', 'last_name']").grep_node(sexp_type: :array)
452
465
  node.array_values.map(&:to_s).should == ["first_name", "last_name"]
453
466
  end
454
467
 
455
468
  it "should get empty array values" do
456
- node = parse_content("[]").grep_node(:sexp_type => :array)
469
+ node = parse_content("[]").grep_node(sexp_type: :array)
457
470
  node.array_values.should == []
458
471
  end
459
472
 
460
473
  it "should get array value with qwords" do
461
- node = parse_content("%w(first_name last_name)").grep_node(:sexp_type => :qwords_add)
474
+ node = parse_content("%w(first_name last_name)").grep_node(sexp_type: :qwords_add)
462
475
  node.array_values.map(&:to_s).should == ["first_name", "last_name"]
463
476
  end
464
477
  end
@@ -466,7 +479,7 @@ describe Sexp do
466
479
  describe "alias" do
467
480
  context "method" do
468
481
  before do
469
- @node = parse_content("alias new old").grep_node(:sexp_type => :alias)
482
+ @node = parse_content("alias new old").grep_node(sexp_type: :alias)
470
483
  end
471
484
 
472
485
  it "should get old_method" do
@@ -480,7 +493,7 @@ describe Sexp do
480
493
 
481
494
  context "symbol" do
482
495
  before do
483
- @node = parse_content("alias :new :old").grep_node(:sexp_type => :alias)
496
+ @node = parse_content("alias :new :old").grep_node(sexp_type: :alias)
484
497
  end
485
498
 
486
499
  it "should get old_method" do
@@ -495,76 +508,81 @@ describe Sexp do
495
508
 
496
509
  describe "to_object" do
497
510
  it "should to array" do
498
- node = parse_content("['first_name', 'last_name']").grep_node(:sexp_type => :array)
511
+ node = parse_content("['first_name', 'last_name']").grep_node(sexp_type: :array)
499
512
  node.to_object.should == ["first_name", "last_name"]
500
513
  end
501
514
 
515
+ it "should to array with %w()" do
516
+ node = parse_content("%w(new create)").grep_node(sexp_type: :array)
517
+ node.to_object.should == ["new", "create"]
518
+ end
519
+
502
520
  it "should to array with symbols" do
503
- node = parse_content("[:first_name, :last_name]").grep_node(:sexp_type => :array)
521
+ node = parse_content("[:first_name, :last_name]").grep_node(sexp_type: :array)
504
522
  node.to_object.should == ["first_name", "last_name"]
505
523
  end
506
524
 
507
525
  it "should to empty array" do
508
- node = parse_content("[]").grep_node(:sexp_type => :array)
526
+ node = parse_content("[]").grep_node(sexp_type: :array)
509
527
  node.to_object.should == []
510
528
  end
511
529
 
512
530
  it "should to string" do
513
- node = parse_content("'richard'").grep_node(:sexp_type => :string_literal)
531
+ node = parse_content("'richard'").grep_node(sexp_type: :string_literal)
514
532
  node.to_object.should == "richard"
515
533
  end
516
534
  end
517
535
 
518
536
  describe "to_s" do
519
537
  it "should get to_s for string" do
520
- node = parse_content("'user'").grep_node(:sexp_type => :string_literal)
538
+ node = parse_content("'user'").grep_node(sexp_type: :string_literal)
521
539
  node.to_s.should == "user"
522
540
  end
523
541
 
524
542
  it "should get to_s for symbol" do
525
- node = parse_content(":user").grep_node(:sexp_type => :symbol_literal)
543
+ node = parse_content(":user").grep_node(sexp_type: :symbol_literal)
526
544
  node.to_s.should == "user"
527
545
  end
528
546
 
529
547
  it "should get to_s for const" do
530
- node = parse_content("User").grep_node(:sexp_type => :@const)
548
+ node = parse_content("User").grep_node(sexp_type: :@const)
531
549
  node.to_s.should == "User"
532
550
  end
533
551
 
534
552
  it "should get to_s for ivar" do
535
- node = parse_content("@user").grep_node(:sexp_type => :@ivar)
553
+ node = parse_content("@user").grep_node(sexp_type: :@ivar)
536
554
  node.to_s.should == "@user"
537
555
  end
538
556
 
539
557
  it "should get to_s for class with module" do
540
- node = parse_content("ActiveRecord::Base").grep_node(:sexp_type => :const_path_ref)
558
+ node = parse_content("ActiveRecord::Base").grep_node(sexp_type: :const_path_ref)
541
559
  node.to_s.should == "ActiveRecord::Base"
542
560
  end
543
561
 
544
562
  it "should get to_s for label" do
545
- node = parse_content("{first_name: 'Richard'}").grep_node(:sexp_type => :@label)
563
+ node = parse_content("{first_name: 'Richard'}").grep_node(sexp_type: :@label)
546
564
  node.to_s.should == "first_name"
547
565
  end
548
566
 
549
567
  it "should get to_s for call" do
550
- node = parse_content("current_user.post").grep_node(:sexp_type => :call)
568
+ node = parse_content("current_user.post").grep_node(sexp_type: :call)
551
569
  node.to_s.should == "current_user.post"
552
570
  end
553
571
  end
554
572
 
555
573
  describe "const?" do
556
574
  it "should return true for const with var_ref" do
557
- node = parse_content("User.find").grep_node(:sexp_type => :var_ref)
575
+ node = parse_content("User.find").grep_node(sexp_type: :var_ref)
558
576
  node.should be_const
559
577
  end
560
578
 
561
579
  it "should return true for const with @const" do
562
- node = parse_content("User.find").grep_node(:sexp_type => :@const)
580
+ node = parse_content("User.find").grep_node(sexp_type: :@const)
563
581
  node.should be_const
564
582
  end
565
583
 
566
584
  it "should return false for ivar" do
567
- node = parse_content("@user.find").grep_node(:sexp_type => :@ivar)
585
+ node = parse_content("@user.find").grep_node(sexp_type: :@ivar)
568
586
  node.should_not be_const
569
587
  end
570
588
  end