Created
June 25, 2015 08:06
-
-
Save myronmarston/a553f22ce5f2a7d058ec to your computer and use it in GitHub Desktop.
Example specs for https://groups.google.com/forum/#!topic/rspec/GndcucJCgEM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Sentence | |
def test(sen) | |
first = sen[0] | |
last = sen.split('').last | |
rest = sen[1..-1] | |
word_arr = sen.split | |
word_arr_len = word_arr.length | |
unless first == first.upcase then | |
puts "the first letter is not in uppercase" | |
end | |
if word_arr_len == 1 then | |
puts "there must be spaces between words" | |
end | |
unless last == "." || last = last.upcase then | |
puts "the sentence should end with a full stop" | |
end | |
unless (sen =~ /[A-Z]{2,}/) == nil then | |
puts "no two consecutive upper case letters are allowed" | |
end | |
unless sen == word_arr.join(" ") then | |
puts "no two consecutive spaces are allowed" | |
end | |
end | |
end | |
RSpec.describe Sentence do | |
let(:sentence) { Sentence.new } | |
it "prints nothing when given a valid sentence" do | |
expect { | |
sentence.test("Hello world.") | |
}.not_to output.to_stdout | |
end | |
it "requires the first word to be capitalized" do | |
expect { | |
sentence.test("hello world.") | |
}.to output(/first letter is not in uppercase/).to_stdout | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello Myron,
Thank you so much for the solved code!