should_clean 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,8 +5,7 @@ module ShouldClean
5
5
  # order of convertors matter
6
6
  convertors = [
7
7
  Converters::NegativeConverter,
8
- Converters::AdverbConverter,
9
- Converters::RegularVerbConverter
8
+ Converters::PositiveConverter
10
9
  ]
11
10
 
12
11
  convertor = convertors.detect { |converter| text.match(converter.matcher) }
@@ -2,7 +2,6 @@ module ShouldClean
2
2
  module Converters
3
3
  autoload :Converter, 'should_clean/converters/converter'
4
4
  autoload :NegativeConverter, 'should_clean/converters/negative_converter'
5
- autoload :RegularVerbConverter, 'should_clean/converters/regular_verb_converter'
6
- autoload :AdverbConverter, 'should_clean/converters/adverb_converter'
5
+ autoload :PositiveConverter, 'should_clean/converters/positive_converter'
7
6
  end
8
7
  end
@@ -1,18 +1,66 @@
1
1
  module ShouldClean
2
2
  module Converters
3
3
  class Converter
4
- attr_accessor :text, :match_data
4
+ SUBJECT = /^\s*(it\s*'|it\s*"|it\s*%{)\s*/
5
+ NEGATIVE_SPEC = /#{SUBJECT}(should not|shouldn't)\s*/
6
+ POSITIVE_SPEC = /#{SUBJECT}(should)\s*/
7
+
8
+ attr_accessor :text, :splitter
5
9
 
6
10
  def initialize(text, match_data)
7
11
  @text = text
8
- @match_data = match_data
12
+ @splitter = match_data[2]
13
+ end
14
+
15
+ def convert
16
+ "#{subject}#{active_verb}#{joiner}#{object}"
9
17
  end
10
18
 
11
19
  private
12
- def splitter
13
- match_data[0]
20
+ def verb
21
+ @verb ||= verb_and_object.first
22
+ end
23
+
24
+ def adverb
25
+ @adverb = ShouldClean::Adverbs.all.detect do |a|
26
+ adverb_and_expectation.lstrip.start_with?(a)
27
+ end
14
28
  end
15
29
 
30
+ def subject
31
+ @subject = subject_and_expectation.first
32
+ end
33
+
34
+ def object
35
+ @object ||= verb_and_object.last
36
+ end
37
+
38
+ def joiner
39
+ expectation.lstrip.split(/\W/, 2) # split limit gives the regexp match $&
40
+ @joiner = $&
41
+ end
42
+
43
+ def expectation
44
+ return @expectation if @expectation
45
+
46
+ if adverb
47
+ @expectation = adverb_and_expectation.split(adverb).last
48
+ else
49
+ @expectation = adverb_and_expectation
50
+ end
51
+ end
52
+
53
+ def adverb_and_expectation
54
+ @adverb_and_expectation ||= subject_and_expectation.last
55
+ end
56
+
57
+ def verb_and_object
58
+ @verb_and_object ||= expectation.lstrip.split(/\W/, 2)
59
+ end
60
+
61
+ def subject_and_expectation
62
+ @subject_and_expectation ||= text.split(splitter, 2)
63
+ end
16
64
  end
17
65
  end
18
66
  end
@@ -3,13 +3,21 @@ module ShouldClean
3
3
  class NegativeConverter < Converter
4
4
 
5
5
  def self.matcher
6
- /should( not|n't)/
6
+ /#{NEGATIVE_SPEC}/
7
7
  end
8
8
 
9
- def convert
10
- text.gsub(splitter, 'does not')
9
+ private
10
+ def active_verb
11
+ if verb == 'be'
12
+ if adverb == 'by default'
13
+ @active_verb = 'does not default to'
14
+ else
15
+ @active_verb = 'is not'
16
+ end
17
+ else
18
+ @active_verb = ['does not', adverb, verb].compact.join(' ')
19
+ end
11
20
  end
12
-
13
21
  end
14
22
  end
15
23
  end
@@ -0,0 +1,22 @@
1
+ module ShouldClean
2
+ module Converters
3
+ class PositiveConverter < Converter
4
+
5
+ def self.matcher
6
+ /#{POSITIVE_SPEC}/
7
+ end
8
+
9
+ private
10
+ def active_verb
11
+ return @active_verb if @active_verb
12
+
13
+ if adverb == 'by default' && verb == 'be'
14
+ @active_verb = "defaults to"
15
+ else
16
+ active_verb = Conjugator.tpp(verb)
17
+ @active_verb = [adverb, active_verb].compact.join(' ')
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -3,8 +3,6 @@ require 'tempfile'
3
3
 
4
4
  module ShouldClean
5
5
  class Replacer
6
- MATCHER = /^it\s*('|"|%{)/
7
-
8
6
  attr_accessor :file_path, :content
9
7
 
10
8
  def initialize(file_path)
@@ -18,12 +16,8 @@ module ShouldClean
18
16
  tmp_file = Tempfile.new('tmp.txt')
19
17
 
20
18
  content.each_line.each do |line|
21
- if line.strip.match(MATCHER)
22
- cleaned = Cleaner.clean(line)
23
- tmp_file.puts cleaned || line
24
- else
25
- tmp_file.puts line
26
- end
19
+ cleaned = Cleaner.clean(line)
20
+ tmp_file.puts cleaned || line
27
21
  end
28
22
 
29
23
  tmp_file.close
@@ -3,8 +3,6 @@ require 'tempfile'
3
3
 
4
4
  module ShouldClean
5
5
  class Simulator
6
- MATCHER = /^it\s*('|"|%{)/
7
-
8
6
  attr_accessor :content, :buffer
9
7
 
10
8
  def initialize(file_path, buffer = $stdout)
@@ -16,12 +14,10 @@ module ShouldClean
16
14
  return unless content.valid_encoding?
17
15
 
18
16
  content.each_line.each do |line|
19
- if line.strip.match(MATCHER)
20
- cleaned = Cleaner.clean(line)
21
- if cleaned
22
- buffer.puts("- #{line.strip}")
23
- buffer.puts("+ #{cleaned.strip}")
24
- end
17
+ cleaned = Cleaner.clean(line)
18
+ if cleaned
19
+ buffer.puts("- #{line.strip}")
20
+ buffer.puts("+ #{cleaned.strip}")
25
21
  end
26
22
  end
27
23
  end
@@ -1,3 +1,3 @@
1
1
  module ShouldClean
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe ShouldClean::Cleaner do
4
4
 
5
- describe "normal conversion from future to present tense" do
5
+ describe "regular verb converter" do
6
6
  it "converts spec defined with double quotes" do
7
7
  ShouldClean::Cleaner.clean('it "should action something"').
8
8
  should == 'it "actions something"'
@@ -22,26 +22,14 @@ describe ShouldClean::Cleaner do
22
22
  ShouldClean::Cleaner.clean('it "should do something"').
23
23
  should == 'it "does something"'
24
24
  end
25
- end
26
-
27
- describe "conversion of should variations" do
28
- it "converts 'should not action' to 'does not action'" do
29
- ShouldClean::Cleaner.clean('it "should not action"').
30
- should == 'it "does not action"'
31
- end
32
-
33
- it "converts 'shouldn't action' to 'does not action'" do
34
- ShouldClean::Cleaner.clean('it "shouldn\'t action"').
35
- should == 'it "does not action"'
36
- end
37
25
 
38
26
  it "converts 'should be able to action' to 'actions'" do
39
27
  ShouldClean::Cleaner.clean('it "should be able to action"').
40
- should == 'it "actions"'
28
+ should == 'it "is able to action"'
41
29
  end
42
30
  end
43
31
 
44
- describe "conversion of adverbs" do
32
+ describe "positive converter with adverb" do
45
33
  it "converts 'should correctly calculate' to 'correctly calculates'" do
46
34
  ShouldClean::Cleaner.clean('it "should correctly calculate"').
47
35
  should == 'it "correctly calculates"'
@@ -66,5 +54,56 @@ describe ShouldClean::Cleaner do
66
54
  ShouldClean::Cleaner.clean('it "should by default have"').
67
55
  should == 'it "by default has"'
68
56
  end
57
+
58
+ it "converts 'should by default be 1' to 'defaults to 1'" do
59
+ ShouldClean::Cleaner.clean('it "should by default be 1"').
60
+ should == 'it "defaults to 1"'
61
+ end
62
+
63
+ it "converts 'should automatically be 1' to 'automatically is 1'" do
64
+ ShouldClean::Cleaner.clean('it "should automatically be 1"').
65
+ should == 'it "automatically is 1"'
66
+ end
67
+ end
68
+
69
+ describe "negative converter" do
70
+ it "converts 'should not action' to 'does not action'" do
71
+ ShouldClean::Cleaner.clean('it "should not action"').
72
+ should == 'it "does not action"'
73
+ end
74
+
75
+ it "converts 'shouldn't action' to 'does not action'" do
76
+ ShouldClean::Cleaner.clean('it "shouldn\'t action"').
77
+ should == 'it "does not action"'
78
+ end
79
+
80
+ it "converts 'should not be foo' to 'is not foo'" do
81
+ ShouldClean::Cleaner.clean('it "should not be foo"').
82
+ should == 'it "is not foo"'
83
+ end
84
+
85
+ it "converts 'shouldn't be foo' to 'is not foo'" do
86
+ ShouldClean::Cleaner.clean('it "shouldn\'t be foo"').
87
+ should == 'it "is not foo"'
88
+ end
89
+ end
90
+
91
+ describe "negative converter with adverb" do
92
+ it "converts 'should not automatically save' to 'does not automatically save'" do
93
+ ShouldClean::Cleaner.clean('it "should not automatically save"').
94
+ should == 'it "does not automatically save"'
95
+ end
96
+
97
+ it "converts 'should not by default be 1' to 'does not default to 1'" do
98
+ ShouldClean::Cleaner.clean('it "should not by default be 1"').
99
+ should == 'it "does not default to 1"'
100
+ end
101
+ end
102
+
103
+ describe "no change required" do
104
+ it "constrain changes to beginning of doc string" do
105
+ ShouldClean::Cleaner.clean('it "asks for a failure_message_for_should when something"').
106
+ should == nil
107
+ end
69
108
  end
70
109
  end
metadata CHANGED
@@ -1,46 +1,43 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: should_clean
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 0
8
- - 2
9
- version: 0.0.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Sachin Ranchod
13
9
  - Dalibor Nasevic
14
10
  autorequire:
15
11
  bindir: bin
16
12
  cert_chain: []
17
-
18
- date: 2012-09-06 00:00:00 +02:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
13
+ date: 2012-09-10 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
22
16
  name: rspec
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- segments:
29
- - 0
30
- version: "0"
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
31
23
  type: :development
32
- version_requirements: *id001
33
- description: Utility to remove unneeded shoulds from your RSpec test descriptions - 'it "should do something"' becomes 'it "does something"'
34
- email:
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
31
+ description: Utility to remove unneeded shoulds from your RSpec test descriptions
32
+ - 'it "should do something"' becomes 'it "does something"'
33
+ email:
35
34
  - sachin.ranchod@gmail.com
36
35
  - dalibor.nasevic@gmail.com
37
- executables:
36
+ executables:
38
37
  - should_clean
39
38
  extensions: []
40
-
41
39
  extra_rdoc_files: []
42
-
43
- files:
40
+ files:
44
41
  - .gitignore
45
42
  - .rspec
46
43
  - Gemfile
@@ -53,10 +50,9 @@ files:
53
50
  - lib/should_clean/cleaner.rb
54
51
  - lib/should_clean/conjugator.rb
55
52
  - lib/should_clean/converters.rb
56
- - lib/should_clean/converters/adverb_converter.rb
57
53
  - lib/should_clean/converters/converter.rb
58
54
  - lib/should_clean/converters/negative_converter.rb
59
- - lib/should_clean/converters/regular_verb_converter.rb
55
+ - lib/should_clean/converters/positive_converter.rb
60
56
  - lib/should_clean/replacer.rb
61
57
  - lib/should_clean/simulator.rb
62
58
  - lib/should_clean/version.rb
@@ -72,37 +68,31 @@ files:
72
68
  - spec/should_clean/simulator_spec.rb
73
69
  - spec/should_clean_spec.rb
74
70
  - spec/spec_helper.rb
75
- has_rdoc: true
76
- homepage: ""
71
+ homepage: ''
77
72
  licenses: []
78
-
79
73
  post_install_message:
80
74
  rdoc_options: []
81
-
82
- require_paths:
75
+ require_paths:
83
76
  - lib
84
- required_ruby_version: !ruby/object:Gem::Requirement
85
- requirements:
86
- - - ">="
87
- - !ruby/object:Gem::Version
88
- segments:
89
- - 0
90
- version: "0"
91
- required_rubygems_version: !ruby/object:Gem::Requirement
92
- requirements:
93
- - - ">="
94
- - !ruby/object:Gem::Version
95
- segments:
96
- - 0
97
- version: "0"
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
98
89
  requirements: []
99
-
100
90
  rubyforge_project:
101
- rubygems_version: 1.3.6
91
+ rubygems_version: 1.8.23
102
92
  signing_key:
103
93
  specification_version: 3
104
94
  summary: It changes "it should do" to "it does" in your RSpec files
105
- test_files:
95
+ test_files:
106
96
  - spec/fixtures/broken_spec.txt
107
97
  - spec/fixtures/example_correct_spec.txt
108
98
  - spec/fixtures/example_spec.txt
@@ -1,23 +0,0 @@
1
- module ShouldClean
2
- module Converters
3
- class AdverbConverter < Converter
4
-
5
- def self.matcher
6
- /should (#{ShouldClean::Adverbs.all.join('|')})/
7
- end
8
-
9
- def convert
10
- prefix, postfix = text.split(splitter, 2)
11
- verb, remainder = postfix.lstrip.split(/\W/, 2) # split limit gives the regexp match $&
12
- active_verb = Conjugator.tpp(verb)
13
- "#{prefix}#{adverb} #{active_verb}#{$&}#{remainder}"
14
- end
15
-
16
- private
17
- def adverb
18
- match_data[1]
19
- end
20
-
21
- end
22
- end
23
- end
@@ -1,18 +0,0 @@
1
- module ShouldClean
2
- module Converters
3
- class RegularVerbConverter < Converter
4
-
5
- def self.matcher
6
- /should (be able to)?/
7
- end
8
-
9
- def convert
10
- method_name, description = text.split(splitter, 2)
11
- verb, rest = description.lstrip.split(/\W/, 2) # split limit gives the regexp match $&
12
- active_verb = Conjugator.tpp(verb)
13
- "#{method_name}#{active_verb}#{$&}#{rest}"
14
- end
15
-
16
- end
17
- end
18
- end