I have an rspec test on a pure Ruby model:
require 'spec_helper'
require 'organization'
describe Organization do
context '#is_root?' do
it "creates a root organization" do
org = Organization.new
expect { org.is_root?.to eq true }
end
end
end
My organization model looks like this:
class Organization
attr_accessor :parent
def initialize(parent = nil)
self.parent = parent
end
end
The output when running the tests:
bundle exec rspec spec/organization_spec.rb:6
Run options: include {:locations=>{"./spec/organization_spec.rb"=>[6]}}
.
Finished in 0.00051 seconds
1 example, 0 failures
When I run the test, it passes, despite the fact that the method is_root? doesn't exist on the model. I usually work in Rails, not pure Ruby, and I've never seen this happen. What is going on?
Thanks!
rails consoleand asko.methods.select do |m| m.match /root/ endto verify your assumption aboutis_root?- Patru1) Organization#is_root? creates a root organization Failure/Error: org.method(:is_root?) NameError: undefined methodis_root?' for classOrganization' # ./spec/organization_spec.rb:10:inmethod' # ./spec/organization_spec.rb:10:inblock (3 levels) in <top (required)>'- rainslg