Search code examples
ruby-on-railsrspectddintegration-testingbdd

How to learn spec type from helper method?


I'm writing specs from my little website, and I stuck with a little problem.

I have some spec helper methods, like:

  def is_logged_in?(spec = :feature)
    if spec == :feature
      page.has_selector?('#user-menu')
    else
      !session[:user_id].nil?
    end
  end

But I'm tired of passing the "spec" argument, and I think that there is better solution, like: if current_spec.type == :feature ....

Is there a way to learn type of current running spec from helper method?


Solution

  • Okay, I figured out how to distinguish feature spec from other specs:

    def feature_test?
      defined?(visit)
    end
    

    And it fits my code well =-)