Permalink
Browse files

Treat missing/nil controller assigns differently; fixed gh-124 (based…

… on patch from James McCarthy)
  • Loading branch information...
1 parent a839bf5 commit b0692c397814ec7d2aeb3a15b927582493c859a2 @jferris jferris committed Aug 17, 2010
@@ -22,7 +22,8 @@ def assign_to(variable)
class AssignToMatcher # :nodoc:
def initialize(variable)
- @variable = variable.to_s
+ @variable = variable.to_s
+ @check_value = false
end
def with_kind_of(expected_class)
@@ -31,7 +32,8 @@ def with_kind_of(expected_class)
end
def with(expected_value = nil, &block)
- @expected_value = expected_value
+ @check_value = true
+ @expected_value = expected_value
@expectation_block = block
self
end
@@ -58,7 +60,7 @@ def in_context(context)
private
def assigned_value?
- if assigned_value.nil?
+ if !@controller.instance_variables.include?("@#{@variable}")
@failure_message =
"Expected action to assign a value for @#{@variable}"
false
@@ -87,7 +89,7 @@ def kind_of_expected_class?
end
def equal_to_expected_value?
- return true unless @expected_value
+ return true unless @check_value
if @expected_value == assigned_value
@negative_failure_message =
"Didn't expect action to assign #{@expected_value.inspect} " <<
@@ -42,4 +42,14 @@ class AssignToMatcherTest < ActionController::TestCase # :nodoc:
end
end
+ context "a controller that assigns a nil value to an instance variable" do
+ setup do
+ @controller = build_response { @var = nil }
+ end
+
+ should "accept assigning to that variable" do
+ assert_accepts assign_to(:var), @controller
+ end
+ end
+
end

0 comments on commit b0692c3

Please sign in to comment.