Creating a context in custom shoulda macro does not work.
- by Honza
I have a custom should macro in my test_helper.rb which looks like this.
def self.should_require_login(actions = [:index])
if (actions.is_a? Symbol)
actions = [actions]
end
context "without user" do
actions.each do |action|
should "redirect #{action.to_s} away" do
get action
assert_redirected_to login_path
end
end
end
if block_given?
context "active user logged in" do
setup do
@user = Factory.create(:user)
@user.register!
@user.activate!
login_as(@user)
end
yield
end
end
end
I would like to use it like this:
should_require_login(:protected_action) do
should "do something" do
...
end
end
And I am expecting the "do something" test to run in the "active user logged in" context, but the test executes in the top context, like the "active user logged in" context never existed and I fail to see the reason why.