Skip to content

Add view spec helpers (similar to devise) #107

Description

@RowanMcDonald

Problem:

I would like to be able to render partials with test track flags in them in view specs.

Details:

With devise, you can use their controller helpers in your view specs like:

RSpec.configure do |config|
  config.include Devise::Test::ControllerHelpers, type: /controller|view/
end

This gives you access to their global setters and getters for user authentication. Thus if your view requires current_user you can set it up in your test.

Like devise, Test track also relies on methods that are globally accessible in rails rendering pipeline.

Work around

We have a work around where we monkey patch the test controller like this:

RSpec.configure do |config|
  config.before(:suite) do
    class ActionView::TestCase::TestController
      include TestTrack::Controller
      self.test_track_identity = :current_user # user, manager, ...
    end
  end
end

Proposed solution

I think it would be helpful if the test_track_rails_client were to expose a some sort of test helper module for this purpose. That way we could write something like:

RSpec.configure do |config|
  config.include TestTrack::Test::ViewHelpers, type: :view
end

One small hitch is that the authorized user is currently configured at the controller level (self.test_track_identity). Devise doesn't have this problem because the define their "default scope" in an initializer:

Devise.setup do |config|
  config.default_scope = :user
end

A couple of ways we could handle this:

  1. Define a fake test_track_visitor so that you can use the existing test helper stub_test_track_assignments ...
  2. Move self.test_track_identity into an initializer.
  3. Use a module builder like
RSpec.configure do |config|
  config.include TestTrack::Test::ViewHelpers.for(:current_plan_manager), type: :view
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions