Valid characters in method names
2007-12-10
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.
blog comments powered by Disqus