TestFirst Learn Ruby Simon Says

657 Views Asked by At

I'm doing TestFirst.org's Learn Ruby tutorial and am currently on exercise number 3 Simon Says. I'm not sure if this is a problem or if it's interfering with my tests (and giving me the wrong results) using rspec, but the terminal prints out some error messages before it shows that all my tests have passed.

caitlyns-mbp:03_simon_says caitlynyu$ rake
(in /Users/caitlynyu/Desktop/learn_ruby)
/Users/caitlynyu/Desktop/learn_ruby/03_simon_says/simon_says_spec.rb:62: warning: possibly useless use of == in void context
/Users/caitlynyu/Desktop/learn_ruby/03_simon_says/simon_says_spec.rb:63: warning: possibly useless use of == in void context

Run options: include {:focus=>true}

All examples were filtered out; ignoring {:focus=>true}

Simon says
  repeat
    should repeat
    should repeat a number of times
  echo
    should echo hello
    should echo bye
  start_of_word
    returns the first letter
    returns the first several letters
    returns the first two letters
  shout
    should shout hello
    should shout multiple words
  first_word
    tells us the first word of 'Hello World' is 'Hello'
    tells us the first word of 'oh dear' is 'oh'
  titleize
    doesn't capitalize 'little words' in a title
    does capitalize 'little words' at the start of a title
    capitalizes every word (aka title case)
    capitalizes a word

Finished in 0.00324 seconds
15 examples, 0 failures

Randomized with seed 36160

It gives a warning for the simon_says_spec.rb but this is the spec provided by the TestFirst Learn Ruby tutorial. Why is there a problem with this? Also, is it a big issue that it says 'All examples were filtered out; ignoring {:focus=>true|}'?

2

There are 2 best solutions below

0
On

The errors are likely due to you using RSpec 3 while the tests were written for RSpec 2, but you should be able to safely ignore them. The ignoring message is supposed to be there, as explained in the RSpec documentation.

0
On

One of the problem's with rspec's operator matcher

foo.should == bar

Is that it produced the warning you got. Ruby thinks the == is useless because it's not being returned, isn't in an if etc: it thinks the you are just doing a normal comparison but not using the result. At the point where ruby does this warning checking it doesn't realise that rspec has redefined == on the object returned by should and that as a result it isn't useless.

To avoid this warning you can use the eq matcher instead, both with or without the expect syntax introduced in rspec 2.12:

foo.should eq(bar)
expect(foo).to eq(bar)

You can also turn off warnings (rspec 3 defaulted to turning on warnings in the .rspec file but I believe this is being reverted)

The warning about filtering is not a problem.