samedi 21 mars 2015

NoMethodError when running RSpec test

I am getting the error NoMethodError when trying to use RSpec for testing the gem I created.


this is my gem: ~/project/gemz/spec/lib/checksomething.rb



class Checkpercentage

#1) what is x% of y?
def self.findAmount(rate, base)
resultAmount = rate * base/100
return resultAmount

end

#2) x is what percentage of y?
def self.findPercent(amount, base)
resultPercent = amount/base * 100
return resultPercent
end

#3) x is y% of what number?
def self.findBase(amount, rate)
resultBase = amount/rate *100
return resultBase
end
end # End Module


And this is my rspec test file: ./project/gemz/spec/lib/checkpercentage_spc.rb



require "spec_helper"
require "checksomething"

RSpec.describe Checkpercentage, '#intNum' do
context "with no integer entered" do
it "must be a number" do
checkpercentage = Checkpercentage.new
checkpercentage.findPercent(100, 200)
expect(checkpercentage.intNum) > 0
end
end
end


I want to test if the values enterend in the findPercentage method are > 0. However, when I run the rspec command in my terminal (rspec spec/lib/checkpercentage_spc.rb) the following error comes up:



Failures:

1) Checkpercentage#intNum with no integer entered must be a number
Failure/Error: 20.times {checkpercentage.findPercent(100, 200)}
NoMethodError:
undefined method `findPercent' for #<Checkpercentage:0xad3de84>
# ./spec/lib/checkpercentage_spc.rb:8:in `block (4 levels) in <top (required)>'
# ./spec/lib/checkpercentage_spc.rb:8:in `times'
# ./spec/lib/checkpercentage_spc.rb:8:in `block (3 levels) in <top (required)>'

Finished in 0.00118 seconds (files took 0.66969 seconds to load)
1 example, 1 failure

Failed examples:

rspec ./spec/lib/checkpercentage_spc.rb:6 # Checkpercentage#intNum with no integer entered must be a number


I'm fairly new at ruby on rails. Can anyone point me to the right direction? Any help is appreciated.


Aucun commentaire:

Enregistrer un commentaire