Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #43 from tiegz/no_ancestor_const_get

described_type: no ancestor lookup for constants that don't exist
  • Loading branch information...
commit 872e6fa24d63f5e7b9cd65cf53af03eaa3a3503d 2 parents 488cab1 + f2a17ee
@travisjeffery travisjeffery authored
Showing with 11 additions and 2 deletions.
  1. +3 −1 lib/shoulda/context/context.rb
  2. +8 −1 test/shoulda/context_test.rb
View
4 lib/shoulda/context/context.rb
@@ -210,7 +210,9 @@ def described_type
@described_type ||= self.name.
gsub(/Test$/, '').
split('::').
- inject(Object) { |parent, local_name| parent.const_get(local_name) }
+ inject(Object) do |parent, local_name|
+ parent.const_get(local_name, false)
+ end
end
# Sets the return value of the subject instance method:
View
9 test/shoulda/context_test.rb
@@ -172,13 +172,20 @@ class ::Some
class NestedModel; end
end
-
class Some::NestedModelTest < Test::Unit::TestCase
should "determine the described type for a nested model" do
assert_equal Some::NestedModel, self.class.described_type
end
end
+class Some::SomeTest < Test::Unit::TestCase
+ should "not fallback to higher-level constants with same name" do
+ assert_raises(NameError) do
+ assert_equal nil, self.class.described_type
+ end
+ end
+end
+
class ShouldMatcherTest < Test::Unit::TestCase
class FakeMatcher
attr_reader :subject
Please sign in to comment.
Something went wrong with that request. Please try again.