Skip to content

Commit

Permalink
Accept a context in SetSessionMatcher for use with #to
Browse files Browse the repository at this point in the history
  • Loading branch information
jferris committed Jun 7, 2010
1 parent fa37376 commit 706b633
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Expand Up @@ -19,13 +19,15 @@ def initialize(key)
@key = key.to_s
end

def to(value)
def to(value = nil, &block)
@value = value
@value_block = block
self
end

def matches?(controller)
@controller = controller
@value = @context.instance_eval(&@value_block) if @value_block
(assigned_value? && assigned_correct_value?) || cleared_value?
end

Expand All @@ -43,6 +45,11 @@ def description
description
end

def in_context(context)
@context = context
self
end

private

def assigned_value?
Expand Down
10 changes: 10 additions & 0 deletions test/matchers/controller/set_session_matcher_test.rb
Expand Up @@ -33,6 +33,16 @@ class SetSessionMatcherTest < ActionController::TestCase # :nodoc:
should "accept assigning false to that variable" do
assert_accepts set_session(:false_var).to(false), @controller
end

should "accept assigning to the same value in the test context" do
@expected = 'value'
assert_accepts set_session(:var).to { @expected }, @controller
end

should "reject assigning to the another value in the test context" do
@expected = 'other'
assert_rejects set_session(:var).to { @expected }, @controller
end
end

end

0 comments on commit 706b633

Please sign in to comment.