Hi The convention is put your spec files in the `/spec` directory, with file names matching your application code appended by `_spec.rb`.
For example if you have `lib/sentence.rb`, then you’d have `spec/sentence_spec.rb`. You also generally run RSpec files with the `rspec` command, which by default will run all `_spec.rb` files in the `/spec` directory. Jon Rowe --------------------------- [email protected] jonrowe.co.uk On Thursday, 25 June 2015 at 09:45, Aravindhan A wrote: > Hello Myron, > > Thank you for solving the problem. > > I have few more queries: > > When I copy the code and execute in my remote system, it shows the error > uninitialized constant RSpec. > > I would like to know how to separate out the RSpec file from the class file > and how to run them in command line & what are the naming conventions of > RSpec file. I didn't wrote any RSpec file so far, so your help is required. > > Thanks in advance! > > > > On Thursday, 25 June 2015 13:38:00 UTC+5:30, Myron Marston wrote: > > > > > > 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] > (mailto:[email protected]). > To post to this group, send email to [email protected] > (mailto:[email protected]). > To view this discussion on the web visit > https://groups.google.com/d/msgid/rspec/cee8cd5a-1a6c-4f46-aae0-7693f5fa76bc%40googlegroups.com > > (https://groups.google.com/d/msgid/rspec/cee8cd5a-1a6c-4f46-aae0-7693f5fa76bc%40googlegroups.com?utm_medium=email&utm_source=footer). > For more options, visit https://groups.google.com/d/optout. -- 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/04DBC09662604982A5735C88FE06507F%40jonrowe.co.uk. For more options, visit https://groups.google.com/d/optout.
