Skip to content

Instantly share code, notes, and snippets.

@myronmarston
Created June 25, 2015 08:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save myronmarston/a553f22ce5f2a7d058ec to your computer and use it in GitHub Desktop.
Save myronmarston/a553f22ce5f2a7d058ec to your computer and use it in GitHub Desktop.
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
@aravindhan-a
Copy link

Hello Myron,

Thank you so much for the solved code!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment