ruby on rails - How to properly instantiate a class and call a member method -


i trying write super basic ruby program (new ruby)

in rubymine have project folder named fizzbuzz, have created 2 subfolders, 1 named lib , other named spec.

the lib folder contains 1 class, in turn has 1 member method. here class fizzbuzz:

class fizzbuzz  def fizzbuzz(input)   if !(input % 5 == 0) || !(input % 3 == 0) || !(input % 15 == 0)     return input   else     return 'fizz'   end end 

in spec folder, have following 2 specification tests attempting run:

require 'lib/fizzbuzz'  describe 'fizzbuzz'  'will return number not div 3,5, or 15'    c = fizzbuzz.new    6 == c.fizzbuzz(6) end  'will return fizz when num provided evenly div 3'    d = fizzbuzz.new    'fizz' == d.fizzbuzz(3) end  end 

i keep running following error:

    nameerror: uninitialized constant fizzbuzz     const_missing @ org/jruby/rubymodule.java:2723     const_missing @ c:/jruby-1.7.15/lib/ruby/gems/shared/gems/rspec-core-2.14.8/lib/rspec/core/backward_compatibility.rb:14            (root) @ c:/meehi chai/fizzbuzz/lib/fizzbuzz.rb:1           require @ org/jruby/rubykernel.java:1065           require @ c:/jruby-1.7.15/lib/ruby/shared/rubygems/core_ext/kernel_require.rb:55           require @ c:/jruby-1.7.15/lib/ruby/shared/rubygems/core_ext/kernel_require.rb:53            (root) @ c:/meehi chai/fizzbuzz/spec/fizzbuzz_spec.rb:1              load @ org/jruby/rubykernel.java:1081            (root) @ c:/meehi chai/fizzbuzz/spec/fizzbuzz_spec.rb:1              each @ org/jruby/rubyarray.java:1613            (root) @ c:/jruby-1.7.15/lib/ruby/gems/shared/gems/rspec-core-2.14.8/lib/rspec/core/configuration.rb:1   load_spec_files @ c:/jruby-1.7.15/lib/ruby/gems/shared/gems/rspec-core-2.14.8/lib/rspec/core/configuration.rb:896   load_spec_files @ c:/jruby-1.7.15/lib/ruby/gems/shared/gems/rspec-core-2.14.8/lib/rspec/core/configuration.rb:896               run @ c:/jruby-1.7.15/lib/ruby/gems/shared/gems/rspec-core-2.14.8/lib/rspec/core/command_line.rb:22 

i don't understand uninitialized? have done research , read article here because have not included module? thought project directory, fizzbuzz, module, , since both these 2 rubies contained within it, don't need mention module. please help.

edit: here image of fizzbuzz directory in rubymine, may helpful rubymine

not

class fizzbuzz 

but

class fizzbuzz 

in former case ruby thinks you're trying execute class() method fuzzbuzz constant argument. tries evaluate fizzbuzz first, hence error. if happen have constant defined name error undefined method class.

there few issues tests. there should fizbuzz.new, not fizzbuzz.new. also, not testing anything, executing statements. there should 6.should == c.fizzbuzz(6), or better: expect(c.fizzbuzz(6)).to eq 6.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

c# - How do I get the Nth largest element from a list with duplicates, using LINQ? -

jsp - "Sending a redirect is forbidden after the response has been committed" in sendRedirect -