On Thursday, June 25, 2015 at 12:27:14 AM UTC-7, Aravindhan A wrote:
>
> Hello,
>
> I have come up with the following code. It involves checking a sentence
> with some conditions. I am in need of writing a RSpec for this particular
> file.
>
> 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
>
>
> #test("Simple sentence.")
>
> I want to write a simple RSpec code that passes a value to the test method
> [Similar to the last commented line]. Kindly help me out!
>
> Thanks in advance.
>
The `output` matcher will work well here. I've put together the start of
what the specs could be:
https://gist.github.com/myronmarston/a553f22ce5f2a7d058ec
This includes one spec for the "happy path" case (where it passes all
checks and prints nothing) and one spec for one of the validations. You
should be able to follow the example to come up with specs for the other
validations.
HTH,
Myron
--
You received this message because you are subscribed to the Google Groups
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/rspec/ea07095d-bb8f-4fd6-a93a-9dc03b427f8d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.