Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Change AssignToMatcher to accept a context for use with #with

  • Loading branch information...
commit fa373763b628d77489cc2f39347bd34da5318e95 1 parent 3fe8331
@jferris jferris authored
View
11 lib/shoulda/action_controller/matchers/assign_to_matcher.rb
@@ -30,13 +30,15 @@ def with_kind_of(expected_class)
self
end
- def with(expected_value)
+ def with(expected_value = nil, &block)
@expected_value = expected_value
+ @expectation_block = block
self
end
def matches?(controller)
@controller = controller
+ @expected_value = @context.instance_eval(&@expectation_block) if @expectation_block
assigned_value? && kind_of_expected_class? && equal_to_expected_value?
end
@@ -48,6 +50,11 @@ def description
description
end
+ def in_context(context)
+ @context = context
+ self
+ end
+
private
def assigned_value?
@@ -99,7 +106,7 @@ def assigned_value
end
def assigns
- @controller.response.template.assigns
+ @controller.response.template.assigns
end
end
View
10 test/matchers/controller/assign_to_matcher_test.rb
@@ -30,6 +30,16 @@ class AssignToMatcherTest < ActionController::TestCase # :nodoc:
should "reject assigning to another variable" do
assert_rejects assign_to(:other), @controller
end
+
+ should "accept assigning to the same value in the test context" do
+ @expected = 'value'
+ assert_accepts assign_to(:var).with { @expected }, @controller
+ end
+
+ should "reject assigning to the another value in the test context" do
+ @expected = 'other'
+ assert_rejects assign_to(:var).with { @expected }, @controller
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.