Here is my module in lib/p_table.rb:
class PTable
.
.
.
def convertElmentToMass(el)
@el = Element.find_by_symbol(el)
end
end
Here is my model if it is any relevance in my app/models/element.rb
class Element < ActiveRecord::Base
end
For some reason when I try to test my convertElementToMass function it says uninitialized constant PTable::Element
. It is weird because I should be able to call my model class anywhere right?
Here is my rspec in lib/controllers/module_spec.rb
require 'spec_helper.rb'
require 'p_table'
describe PTable do
class DummyClass
end
before(:all) do
@dummy = DummyClass.new
@dummy.extend PTable
end
describe "testf" do
it "saves the world" do
expect(@dummy.(["Na", '2'])).to eq(2.34)
end
end
end
Use ::Element
instead of Element
only and it will work.
By default, the Rails autoloader will try to find the class internally at the module, by including the ::
you let the system know you want the Element
class at the root module.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With