WestMichiganRubyTraining / discussion

Create issues on this repository to open discussion threads in the Issue Tracker!
2 stars 0 forks source link

undefined method error when using rspec #38

Open atkolkma opened 11 years ago

atkolkma commented 11 years ago

I am almost positive I am doing everything right with regards to rspec syntax. I've checked the documentation a million times. Not sure why I get an undefined method error when I run a very basic rspec test. Here is my spec file:

https://gist.github.com/atkolkma/7516896

When I run it, I get this error:

Failure/Error: expect(fizzbuzzer(9)).to eql("Fizz") NoMethodError: undefined method `fizzbuzzer' for #

./fizzbuzz_spec.rb:7:in`block (3 levels) in <top (required)>'

I'm testing the fizzbuzz.rb file from the repo that was posted for testing purposes. Also, there is no load error for fizzbuzz.rb

atkolkma commented 11 years ago

I just got the test to pass by calling fizzbuzzer on an instantiation of FizzBuzz.

billgathen commented 11 years ago

Good job pushing through it! Since you used the describe FizzBuzz style (instead of passing a string to describe), you automatically get a "subject" variable that's an instance of the class under test, so you could do this, too:

expect(subject.fizzbuzzer(9)).to eql("Fizz")

Some people don't care for the "free" instance, and it doesn't work if you need to pass config data into your constructor, but it's worth knowing about and usable in this situation.

Also worth mentioning is that eql can be shortened to just eq: apparently they're equivalent. I wasn't aware of the three-letter variant.

matthew-p commented 11 years ago

so, this yes? https://www.relishapp.com/rspec/rspec-core/v/3-0/docs/subject/implicitly-defined-subject

billgathen commented 11 years ago

@matthew-p Exactly!