I was writing a test for a method named hit! and I wrote the following:

1 def test_calling_hit!_increments_hit_count
2   # ...
3 end

Running the tests didn’t pick this up. I renamed the method to:

1 def test_calling_hit_bang_increments_hit_count
2   # ...
3 end

And that obviously worked. So, Ruby accepts ! and ? as suffixes, but not anywhere else. Of course, using Shoulda I wouldn’t have had the problem, since I would have written:

1 context "Calling #hit!" do
2   should "increment the hit counter by one" do
3     # ...
4   end
5 end

Notice the bang is within a String, so no problem there.


Your Host

A picture of me

I am François Beausoleil, a Ruby on Rails and Scala developer. During the day, I work on Seevibes, a platform to measure social interactions related to TV shows. At night, I am interested many things. Read my biography.

Top Tags

Books I read and recommend


Projects I work on

Projects I worked on