style-scanner 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.
Files changed (65) hide show
  1. data/.gitignore +19 -0
  2. data/.rspec +0 -0
  3. data/.rvmrc +1 -0
  4. data/Gemfile +4 -0
  5. data/Rakefile +16 -0
  6. data/bin/style +11 -0
  7. data/lib/dictionaries/acronyms.txt +5 -0
  8. data/lib/dictionaries/cliches.txt +680 -0
  9. data/lib/dictionaries/nationalities.txt +185 -0
  10. data/lib/style_scanner/problems/base.rb +45 -0
  11. data/lib/style_scanner/scanner.rb +67 -0
  12. data/lib/style_scanner/sentence.rb +61 -0
  13. data/lib/style_scanner/sentence_scans/adverb.rb +19 -0
  14. data/lib/style_scanner/sentence_scans/base.rb +70 -0
  15. data/lib/style_scanner/sentence_scans/broken_link.rb +27 -0
  16. data/lib/style_scanner/sentence_scans/capitalization.rb +57 -0
  17. data/lib/style_scanner/sentence_scans/cliche.rb +21 -0
  18. data/lib/style_scanner/sentence_scans/consecutively_repeated_word.rb +22 -0
  19. data/lib/style_scanner/sentence_scans/excess_white_space.rb +22 -0
  20. data/lib/style_scanner/sentence_scans/inappropriate_contraction.rb +20 -0
  21. data/lib/style_scanner/sentence_scans/latin_abbreviation.rb +38 -0
  22. data/lib/style_scanner/sentence_scans/passive_tense.rb +32 -0
  23. data/lib/style_scanner/sentence_scans/speaking_in_generalities.rb +17 -0
  24. data/lib/style_scanner/sentence_scans/spelling.rb +22 -0
  25. data/lib/style_scanner/sentence_scans/ugly_word.rb +17 -0
  26. data/lib/style_scanner/sentence_scans/used_word_already_in_sentence.rb +29 -0
  27. data/lib/style_scanner/sentence_scans/useless_word.rb +17 -0
  28. data/lib/style_scanner/string.rb +33 -0
  29. data/lib/style_scanner/tagged_word.rb +58 -0
  30. data/lib/style_scanner/tagger.rb +25 -0
  31. data/lib/style_scanner/version.rb +3 -0
  32. data/lib/style_scanner.rb +17 -0
  33. data/readme.textile +157 -0
  34. data/spec/fixtures/sample_text.txt +2 -0
  35. data/spec/fixtures/stylish/economist/economist-1.txt +29 -0
  36. data/spec/fixtures/stylish/economist/economist-2.txt +21 -0
  37. data/spec/fixtures/stylish/economist/economist-3.txt +9 -0
  38. data/spec/fixtures/stylish/economist/economist-4.txt +23 -0
  39. data/spec/fixtures/stylish/economist/economist-5.txt +15 -0
  40. data/spec/fixtures/stylish/economist/economist-6.txt +37 -0
  41. data/spec/integrations/command_line_spec.rb +41 -0
  42. data/spec/problems/base_spec.rb +38 -0
  43. data/spec/scanner_spec.rb +41 -0
  44. data/spec/sentence_scans/adverb_spec.rb +13 -0
  45. data/spec/sentence_scans/base_spec.rb +18 -0
  46. data/spec/sentence_scans/broken_link_spec.rb +18 -0
  47. data/spec/sentence_scans/capitalization_spec.rb +44 -0
  48. data/spec/sentence_scans/cliche_spec.rb +35 -0
  49. data/spec/sentence_scans/consecutively_repeated_word_spec.rb +26 -0
  50. data/spec/sentence_scans/excess_white_space_spec.rb +22 -0
  51. data/spec/sentence_scans/inappropriate_contraction_spec.rb +21 -0
  52. data/spec/sentence_scans/latin_abbreviation_spec.rb +34 -0
  53. data/spec/sentence_scans/passive_tense_spec.rb +138 -0
  54. data/spec/sentence_scans/speaking_in_generalities_spec.rb +15 -0
  55. data/spec/sentence_scans/spelling_spec.rb +16 -0
  56. data/spec/sentence_scans/ugly_word_spec.rb +29 -0
  57. data/spec/sentence_scans/used_word_already_in_sentence.rb +21 -0
  58. data/spec/sentence_scans/useless_word_spec.rb +14 -0
  59. data/spec/sentence_spec.rb +76 -0
  60. data/spec/spec_helper.rb +26 -0
  61. data/spec/string_spec.rb +30 -0
  62. data/spec/tagged_word_spec.rb +35 -0
  63. data/spec/tagger_spec.rb +14 -0
  64. data/style-scanner.gemspec +30 -0
  65. metadata +263 -0
@@ -0,0 +1,38 @@
1
+ require "spec_helper"
2
+ module StyleScanner
3
+ module Problems
4
+ describe Base do
5
+ let(:sentence) {Sentence.new("I really like tomatoes.")}
6
+ subject {Base.new(sentence, "really")}
7
+
8
+ it "knows its offending text" do
9
+ subject.offending_text.should == "really"
10
+ end
11
+
12
+ context "#user_friendly_readout" do
13
+ it "is delimited by \ so that cut command will work in linux" do
14
+ subject.user_friendly_readout.split("|").size.should == 3
15
+ end
16
+ it "shows stringified problem name first (taking into colorization)" do
17
+ subject.user_friendly_readout.split("|")[0].strip.should match "Base"
18
+ end
19
+ it "shows problem sentence second" do
20
+ subject.user_friendly_readout.split("|")[1].strip.should match "I really like tomatoes."
21
+ end
22
+ it "shows offending text third" do
23
+ subject.user_friendly_readout.split("|")[2].strip.should match "really"
24
+ end
25
+ end
26
+
27
+ context "#on_text?" do
28
+ it "true if problem is on that word" do
29
+ subject.on_text?("really").should be_true
30
+ end
31
+ it "false if problem is on a different word" do
32
+ subject.on_text?("very").should be_false
33
+ end
34
+ end
35
+
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,41 @@
1
+ require "spec_helper"
2
+ module StyleScanner
3
+ # make sure each example only has one grammatical error
4
+
5
+ describe Scanner do
6
+
7
+ let(:text) { "My name is Roboticus. I am a really powerful robot." }
8
+ subject {Scanner.new(text)}
9
+
10
+ it "#find_sentence" do
11
+ text = "Sentence Number 1. Sentence Number 2"
12
+ sentence = Scanner.new(text).find_sentence("Sentence Number 2")
13
+ sentence.text.should == "Sentence Number 2"
14
+ end
15
+
16
+ context "#scan" do
17
+ it "calls a variety of scans on its sentences" do
18
+ SentenceScans::UselessWord.should_receive(:scan).with(an_instance_of(Sentence)).twice.and_return(double(:sentence))
19
+ subject.scan
20
+ end
21
+ end
22
+
23
+ context "#sentences" do
24
+ it "splits into sentences correctly" do
25
+ sentences = subject.sentences
26
+ sentences.size.should == 2
27
+ last_sentence = sentences[1]
28
+ last_sentence.class.should == Sentence
29
+ last_sentence.text.split.first.should == "I"
30
+ end
31
+ end
32
+
33
+ context "unclosed parenthesis"
34
+ context "uncapitalized starting lines"
35
+ context "forgotten full stop"
36
+ context "overused words"
37
+ context "long words"
38
+ context "passive tense"
39
+
40
+ end
41
+ end
@@ -0,0 +1,13 @@
1
+ require "spec_helper"
2
+ module StyleScanner
3
+ module SentenceScans
4
+ describe Adverb do
5
+ let(:adverb) {Sentence.new "He ran quickly."}
6
+ context "#scan" do
7
+ it "removes 'quickly' from ran quickly" do
8
+ should_problem adverb, Problems::Adverb
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+ module StyleScanner
3
+ module SentenceScans
4
+ describe Base do
5
+ let(:sentence) {Sentence.new("I am a dog.")}
6
+
7
+ context ".scan" do
8
+ it "initializes a new instance of itself and calls scan" do
9
+ new_scanner = double(:base).as_null_object
10
+ Base.should_receive(:new).and_return(new_scanner)
11
+ new_scanner.should_receive(:scan)
12
+ Base.scan(sentence)
13
+
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ require "spec_helper"
2
+ module StyleScanner
3
+ module SentenceScans
4
+ describe BrokenLink do
5
+ let(:working_link) { Sentence.new("View our website: http://www.google.com/")}
6
+ let(:broken_link) { Sentence.new("View our website: http://www.xyasdfasdfsdfas.com/")}
7
+
8
+ context "#scan" do
9
+ it "approves working links" do
10
+ should_not_problem working_link, Problems::BrokenLink
11
+ end
12
+ it "flags broken links" do
13
+ should_problem broken_link, Problems::BrokenLink
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,44 @@
1
+ require "spec_helper"
2
+ module StyleScanner
3
+ module SentenceScans
4
+ describe Capitalization do
5
+
6
+ let(:aids) {Sentence.new("John has aids.")}
7
+ let(:lowercase_first_word) {Sentence.new("he went to the park.")}
8
+ let(:nationality) {Sentence.new("We spoke english.")}
9
+ let(:season) {Sentence.new("We travelled to England in the Summer.")}
10
+ let(:month) {Sentence.new("We travelled to England in march.")}
11
+ let(:uppercase_month) {Sentence.new("We travelled to England in March.")}
12
+ let(:day) {Sentence.new "We arrive on wednesday"}
13
+
14
+ it "catches lowercase months" do
15
+ should_problem month, Problems::Capitalization
16
+ end
17
+ it "doesn't catch uppercase months" do
18
+ should_not_problem uppercase_month, Problems::Capitalization
19
+ end
20
+ it "catches days" do
21
+ should_problem day, Problems::Capitalization
22
+ end
23
+ it "catches first word of sentences" do
24
+ should_problem lowercase_first_word, Problems::Capitalization
25
+ end
26
+ it "flags wrongly capitalized seasons" do
27
+ should_problem season, Problems::Capitalization
28
+ end
29
+ it "catches nationalities and languages" do
30
+ should_problem nationality, Problems::Capitalization
31
+ end
32
+ it "catches acroynms" do
33
+ should_problem aids, Problems::Capitalization
34
+ end
35
+
36
+ pending do
37
+ it "catches placenames"
38
+ it "catches persons names"
39
+ it "catches events"
40
+ end
41
+
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,35 @@
1
+ require "spec_helper"
2
+ module StyleScanner
3
+ module SentenceScans
4
+
5
+ describe Cliche do
6
+ let(:push_envelope_present) {Sentence.new("We need to push the envelope.")}
7
+ let(:push_envelope_present_capitals) {Sentence.new("We need to Push the envelope.")}
8
+ let(:push_envelope_past) {Sentence.new("Our new business pushed the envelope.")}
9
+ let(:push_envelope_gerund) {Sentence.new("We are pushing the envelope here. Seriously.")}
10
+ let(:push_envelope_gerund_capitals) {Sentence.new("We are Pushing the Envelope. Seriously.")}
11
+ let(:throw_envelope) {Sentence.new "We are throwing the envelope."}
12
+
13
+ it "catches present" do
14
+ should_problem push_envelope_present, Problems::Cliche
15
+ end
16
+ it "catches present capital letter cliches" do
17
+ should_problem push_envelope_present_capitals, Problems::Cliche
18
+ end
19
+ it "catches past" do
20
+ should_problem push_envelope_past, Problems::Cliche
21
+ end
22
+ it "catches gerund" do
23
+ should_problem push_envelope_gerund, Problems::Cliche
24
+ end
25
+ it "catches capital letter gerund cliches" do
26
+ should_problem push_envelope_gerund_capitals, Problems::Cliche
27
+ end
28
+ it "doesnt catch non cliches" do
29
+ should_not_problem throw_envelope, Problems::Cliche
30
+ end
31
+
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,26 @@
1
+ require "spec_helper"
2
+ module StyleScanner
3
+ module SentenceScans
4
+
5
+ describe ConsecutivelyRepeatedWord do
6
+
7
+ let(:consecutive_repeated_words) {Sentence.new "I went went to the shop"}
8
+ let(:consecutive_repeated_words_capitalized1) {Sentence.new "I went Went to the shop"}
9
+ let(:consecutive_repeated_words_capitalized2) {Sentence.new "I Went went to the shop"}
10
+
11
+ context "#scan" do
12
+
13
+ it "should remove words repeated in a row" do
14
+ should_problem consecutive_repeated_words, Problems::ConsecutivelyRepeatedWord, "I went to the shop"
15
+ end
16
+
17
+ it "removes words repeated in a row where one is capitalized" do
18
+ should_problem consecutive_repeated_words_capitalized1, Problems::ConsecutivelyRepeatedWord, "I went to the shop"
19
+
20
+ should_problem consecutive_repeated_words_capitalized2, Problems::ConsecutivelyRepeatedWord, "I went to the shop"
21
+ end
22
+
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,22 @@
1
+ require "spec_helper"
2
+ module StyleScanner
3
+ module SentenceScans
4
+ describe ExcessWhiteSpace do
5
+ let(:space_before_stop) {Sentence.new "I ran ."}
6
+ let(:double_spaces) {Sentence.new "It was a place."}
7
+ let(:space_before_comma) {Sentence.new "I ran ,to the fam."}
8
+ context "#scan" do
9
+ it "removes spaces before full stops" do
10
+ should_problem space_before_stop, Problems::ExcessWhiteSpace, "I ran."
11
+ end
12
+ it "removes spaces before commas" do
13
+ should_problem space_before_comma, Problems::ExcessWhiteSpace, "I ran."
14
+ end
15
+ it "removes double spaces" do
16
+ should_problem double_spaces, Problems::ExcessWhiteSpace, "It was a place."
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+
@@ -0,0 +1,21 @@
1
+ require "spec_helper"
2
+ module StyleScanner
3
+ module SentenceScans
4
+ describe InappropriateContraction do
5
+ let(:dont) {Sentence.new "we don't look out."}
6
+ let(:capitalized_dont) {Sentence.new "Don't look out."}
7
+ let(:do_not) {Sentence.new "Do not look out"}
8
+ context "#scan" do
9
+ it "catches don't" do
10
+ should_problem dont, Problems::InappropriateContraction
11
+ end
12
+ it "catches capitalized don't" do
13
+ should_problem capitalized_dont, Problems::InappropriateContraction
14
+ end
15
+ it "does not catch 'does not'" do
16
+ should_not_problem do_not, Problems::InappropriateContraction
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,34 @@
1
+ require "spec_helper"
2
+ module StyleScanner
3
+ module SentenceScans
4
+ describe LatinAbbreviation do
5
+ let(:ie) {Sentence.new "You should not have laughed at him, i.e. he gets angry quickly."}
6
+ let(:ie_without_middle_dot) {Sentence.new "You should not have laughed at him, ie. he gets angry quickly."}
7
+ let(:ie_without_final_dot) {Sentence.new "You should not have laughed at him, i.e he gets angry quickly."}
8
+ let(:ie_without_dots) {Sentence.new "Mario sells cars, motorbikes, cars, ie engine stuff"}
9
+ let(:ie_capitalized) {Sentence.new "Mario sells cars, motorbiks, engines, I.E. he gets angry quickly."}
10
+ let(:double_word_abbreviation) {Sentence.new "We took notes on the cars, et cetera."}
11
+
12
+ context "#scan" do
13
+ it "catches i.e. with proper dot placement" do
14
+ should_problem ie, Problems::LatinAbbreviation
15
+ end
16
+ it "catches ie without middle dot" do
17
+ should_problem ie_without_middle_dot, Problems::LatinAbbreviation
18
+ end
19
+ it "catches ie without final dot" do
20
+ should_problem ie_without_final_dot, Problems::LatinAbbreviation
21
+ end
22
+ it "catches ie without any dots" do
23
+ should_problem ie_without_dots, Problems::LatinAbbreviation
24
+ end
25
+ it "catches ie capitalized" do
26
+ should_problem ie_capitalized, Problems::LatinAbbreviation
27
+ end
28
+ it "catches double word abbreviations like 'et cetera'" do
29
+ should_problem double_word_abbreviation, Problems::LatinAbbreviation
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,138 @@
1
+ require "spec_helper"
2
+ module StyleScanner
3
+ module SentenceScans
4
+ # using examples from: http://www.ego4u.com/en/cram-up/grammar/passive
5
+ describe PassiveTense do
6
+ let(:present) {Sentence.new "A letter is written."}
7
+ let(:simple_past) {Sentence.new "My bike was stolen."}
8
+ let(:present_perfect) {Sentence.new "A letter has been written."}
9
+ let(:future) {Sentence.new "A letter will be written."}
10
+ let(:hilfsverben) {Sentence.new "A letter can be written"}
11
+ let(:present_progressive) {Sentence.new "A letter is being written."}
12
+ let(:past_progressive) {Sentence.new "A letter was being written."}
13
+ let(:past_perfect) {Sentence.new "A letter had been written."}
14
+ let(:conditional_1) {Sentence.new "A letter would be written."}
15
+ let(:conditional_2) {Sentence.new "A letter would have been written."}
16
+
17
+ let(:active_present) {Sentence.new "Rita writes a letter"}
18
+ let(:active_simple_past) {Sentence.new "Rita stoke my bike"}
19
+ let(:active_present_perfect) {Sentence.new "Rita has written a letter."}
20
+ let(:active_future) {Sentence.new "Rita will write a letter."}
21
+ let(:active_hilfsverben) {Sentence.new "Rita can write a letter."}
22
+ let(:active_present_progressive) {Sentence.new "Rita is writing."}
23
+ let(:active_past_progressive) {Sentence.new "Rita was writing."}
24
+ let(:active_past_perfect) {Sentence.new "Rita had written."}
25
+ let(:active_conditional_1) {Sentence.new "Rita would write."}
26
+ let(:active_conditional_2) {Sentence.new "Rite would have written."}
27
+ let(:active_state_with_article) {Sentence.new("The duke is a gonzo journalist sent")}
28
+
29
+ let(:active_state_with_possessive) {Sentence.new("The duke is our saviour.")}
30
+ let(:active_state_with_adverb) {Sentence.new("The devil is really in the details.")}
31
+
32
+ context "#scan" do
33
+ it "catches present passives" do
34
+ should_problem present, Problems::PassiveTense
35
+ end
36
+ it "catches simple_past" do
37
+ should_problem simple_past, Problems::PassiveTense
38
+ end
39
+
40
+ it "catches future" do
41
+ should_problem future, Problems::PassiveTense
42
+ end
43
+
44
+ it "catches hilfsverben" do
45
+ should_problem hilfsverben, Problems::PassiveTense
46
+ end
47
+
48
+ it "catches present_perfect" do
49
+ should_problem present_perfect, Problems::PassiveTense
50
+ end
51
+
52
+
53
+ it "catches present_progressive" do
54
+ should_problem present_progressive, Problems::PassiveTense
55
+ end
56
+
57
+ it "catches past_progressive" do
58
+ should_problem past_progressive, Problems::PassiveTense
59
+ end
60
+
61
+ it "catches past_perfect" do
62
+ should_problem past_perfect, Problems::PassiveTense
63
+ end
64
+
65
+ it "catches present_perfect" do
66
+ should_problem present_perfect, Problems::PassiveTense
67
+ end
68
+
69
+ it "catches conditional_1" do
70
+ should_problem conditional_1, Problems::PassiveTense
71
+ end
72
+
73
+ it "catches conditional_2" do
74
+ should_problem conditional_2, Problems::PassiveTense
75
+ end
76
+
77
+
78
+ it "doesnt catch active_present" do
79
+ should_not_problem active_present, Problems::PassiveTense
80
+ end
81
+
82
+ it "doesnt catch active_simple_past" do
83
+ should_not_problem active_simple_past, Problems::PassiveTense
84
+ end
85
+
86
+ it "doesnt catch active_future" do
87
+ should_not_problem active_future, Problems::PassiveTense
88
+ end
89
+
90
+ it "doesnt catch active_hilfsverben" do
91
+ should_not_problem active_hilfsverben, Problems::PassiveTense
92
+ end
93
+
94
+ it "doesnt catch active_present_perfect" do
95
+ should_not_problem active_present_perfect, Problems::PassiveTense
96
+ end
97
+
98
+ it "doesnt catch active_present_progressive" do
99
+ should_not_problem active_present_progressive, Problems::PassiveTense
100
+ end
101
+
102
+ it "doesnt catch active_past_progressive" do
103
+ should_not_problem active_past_progressive, Problems::PassiveTense
104
+ end
105
+
106
+ it "doesnt catch active_past_perfect" do
107
+ should_not_problem active_past_perfect, Problems::PassiveTense
108
+ end
109
+
110
+ it "doesnt catch active_present_perfect" do
111
+ should_not_problem active_present_perfect, Problems::PassiveTense
112
+ end
113
+
114
+ it "doesnt catch active_conditional_1" do
115
+ should_not_problem active_conditional_1, Problems::PassiveTense
116
+ end
117
+
118
+ it "doesnt catch active_conditional_2" do
119
+ should_not_problem active_conditional_2, Problems::PassiveTense
120
+ end
121
+
122
+ it "doesnt catch active state with article" do
123
+ should_not_problem active_state_with_article, Problems::PassiveTense
124
+ end
125
+
126
+ it "doesnt catch active state with possessive" do
127
+ should_not_problem active_state_with_possessive, Problems::PassiveTense
128
+ end
129
+
130
+ it "doesnt catch active state with adjective between" do
131
+ should_not_problem active_state_with_adverb, Problems::PassiveTense
132
+ end
133
+
134
+
135
+ end
136
+ end
137
+ end
138
+ end
@@ -0,0 +1,15 @@
1
+ require "spec_helper"
2
+ module StyleScanner
3
+ module SentenceScans
4
+ describe SpeakingInGeneralities do
5
+
6
+ let(:mostly) {Sentence.new "The flood was caused mostly by the increased rainfall."}
7
+ context "#scan" do
8
+ it "flags 'mostly'" do
9
+ should_problem mostly, Problems::SpeakingInGeneralities
10
+ end
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,16 @@
1
+ require "spec_helper"
2
+ module StyleScanner
3
+ module SentenceScans
4
+ describe Spelling do
5
+
6
+ let(:incorrect_spelling) {Sentence.new "I was acomodated."}
7
+
8
+ context "#scan" do
9
+ it "catches mispellings" do
10
+ should_problem incorrect_spelling, Problems::Spelling
11
+ end
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,29 @@
1
+ require "spec_helper"
2
+ module StyleScanner
3
+ module SentenceScans
4
+ describe UglyWord do
5
+
6
+ let(:utilize) {Sentence.new("We will utilize these apples.")}
7
+ let(:utilize_uppercase) {Sentence.new("We Utilize Kleenex")}
8
+ let(:utilize_plural) {Sentence.new("She utilizes her brain.")}
9
+ let(:utilize_past) {Sentence.new("She utilized her brain.")}
10
+
11
+ context "#scan" do
12
+ it "recommends you replaces utilize with use" do
13
+ should_problem utilize, Problems::UglyWord, "We will use these apples."
14
+ end
15
+ it "also catches uppercase" do
16
+ should_problem utilize_uppercase, Problems::UglyWord, "We Use Kleenex"
17
+ end
18
+ pending "conjugation awareness" do
19
+ it "also catches plural form" do
20
+ should_problem utilize_plural, Problems::UglyWord, "She uses her brain."
21
+ end
22
+ it "also catches past tense form" do
23
+ should_problem utilize_past, Problems::UglyWord, "She used her brain."
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,21 @@
1
+ require "spec_helper"
2
+ module StyleScanner
3
+ module SentenceScans
4
+ describe UsedWordAlreadyInSentence do
5
+ let(:double_nice) {Sentence.new "It was a nice place, and all the people were nice."}
6
+ let(:consecutive_nice) {Sentence.new "It was a nice nice place."}
7
+ let(:the) {Sentence.new "All through the night leaves were falling, and the moon was dark."}
8
+
9
+ it "flags using the word nice twice" do
10
+ should_problem double_nice, Problems::UsedWordAlreadyInSentence
11
+ end
12
+ it "doesn't flag where you have the word consecutively (since this is a separate error)" do
13
+ should_not_problem consecutive_nice, Problems::UsedWordAlreadyInSentence
14
+ end
15
+ it "doesn't flag common words like 'the'" do
16
+ should_not_problem the, Problems::UsedWordAlreadyInSentence
17
+ end
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,14 @@
1
+ require "spec_helper"
2
+ module StyleScanner
3
+ module SentenceScans
4
+ describe UselessWord do
5
+ let(:very) {Sentence.new "It was a very good idea."}
6
+
7
+ context "#scan" do
8
+ it "removes the word 'very'" do
9
+ should_problem very, Problems::UselessWord, "It was a good idea."
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,76 @@
1
+ require "spec_helper"
2
+ module StyleScanner
3
+ describe Sentence do
4
+ let(:text) {"Christmas shopping shopping for a very big dinosaur."}
5
+ let(:repeated_word_problem) {Problems::ConsecutivelyRepeatedWord.new("shopping shopping", text)}
6
+ let(:ugly_word_problem) {Problems::UglyWord.new("utilize", text)}
7
+ subject { Sentence.new(text) }
8
+
9
+ it "hold a collection of problems" do
10
+ subject.problems.should == []
11
+ end
12
+
13
+ it "lets you access original text" do
14
+ subject.text.should == text
15
+ end
16
+
17
+ context "delegations to string" do
18
+ it "delegates match" do
19
+ subject.match(/shopping/).should_not be_false
20
+ end
21
+ end
22
+
23
+ context "#add_problem" do
24
+ it "adds an problem to the sentence" do
25
+ subject.add_problem(repeated_word_problem)
26
+ subject.problems.first.class.should == Problems::ConsecutivelyRepeatedWord
27
+ end
28
+ end
29
+
30
+ context "#with_problems?" do
31
+ it "true for sentences with problems" do
32
+ subject.problems << double(:problem)
33
+ subject.with_problems?.should be_true
34
+ end
35
+ it "false for sentences without problems" do
36
+ subject.with_problems?.should be_false
37
+ end
38
+ end
39
+
40
+ context "#contains?" do
41
+ let(:flossed) {Sentence.new("I flossed my teeth")}
42
+ it "true if a word is contained within the text" do
43
+ subject.contains?("shopping").should be_true
44
+ end
45
+ it "false if word not contained" do
46
+ subject.contains?("soccer").should be_false
47
+ end
48
+ it "false if only part of a word" do
49
+ subject.contains?("mas").should be_false
50
+ end
51
+ it "stems verbs if option is passed" do
52
+ flossed.contains?("floss", :stem_verbs => true).should be_true
53
+ end
54
+ end
55
+
56
+ context "#to_s" do
57
+ it "displays the text" do
58
+ subject.to_s.should match text
59
+ end
60
+ it "says its a sentence" do
61
+ subject.to_s.should match /Sentence Obj/
62
+ end
63
+ end
64
+
65
+ context "#find_problems_by_type" do
66
+ it "finds the problem according to its class" do
67
+ subject.add_problem(repeated_word_problem)
68
+ subject.add_problem(ugly_word_problem)
69
+ found_problems = subject.find_problems_by_type(Problems::UglyWord)
70
+ found_problems.size.should == 1
71
+ found_problems.first.class.should == Problems::UglyWord
72
+ end
73
+ end
74
+
75
+ end
76
+ end
@@ -0,0 +1,26 @@
1
+ require 'rubygems'
2
+ require 'ruby-debug'
3
+ require 'bundler/setup'
4
+ # Use this when it's a full gem
5
+ require 'style'
6
+
7
+ module StyleScannerTestingHelpers
8
+
9
+ def should_problem(sentence, problem_type, offending_text=nil)
10
+ subject = described_class.new(sentence)
11
+ subject.scan
12
+ problem = sentence.find_problems_by_type(problem_type)
13
+ problem.size.should == 1
14
+ end
15
+
16
+ def should_not_problem(sentence, problem_type)
17
+ subject = described_class.new(sentence)
18
+ subject.scan
19
+ sentence.find_problems_by_type(problem_type).size.should == 0
20
+ end
21
+
22
+ end
23
+
24
+ RSpec.configure do |config|
25
+ config.include(StyleScannerTestingHelpers)
26
+ end