Sha256: aaca02a60b201459c70ca26ffe43e4e3ec9e0f0e07793fcd708865c801a002a4

Contents?: true

Size: 1.58 KB

Versions: 2

Compression:

Stored size: 1.58 KB

Contents

module RSpec
  module Cells
    module ExampleGroup
      extend ActiveSupport::Concern

      include RSpec::Rails::RailsExampleGroup
      include Cell::Testing
      include ActionController::UrlFor

      attr_reader :routes

      def method_missing(method, *args, &block)
        # Send the route helpers to the application router.
        if route_defined?(method)
          controller.send(method, *args, &block)
        else
          super
        end
      end

      def route_defined?(method)
        return false unless @routes

        if @routes.named_routes.respond_to?(:route_defined?) # Rails > 4.2.
          @routes.named_routes.route_defined?(method)
        else
          @routes.named_routes.helpers.include?(method)
        end
      end

      included do
        metadata[:type] = :cell

        before do # called before every it.
          @routes = ::Rails.application.routes
          ActionController::Base.allow_forgery_protection = false
        end

        # add Example::controller and ::controller_class.
        extend RSpec::Cells::ExampleGroup::Controller
        let (:controller_class) {  }
        let (:controller) { controller_for(controller_class) }
      end


      module Controller
        def controller(name) # DSL for test, e.g. `controller SongsController`.
          let (:controller_class) { name }
        end
      end
    end
  end
end

RSpec.configure do |c|
  c.include RSpec::Cells::ExampleGroup, :file_path => /spec\/cells/
  c.include RSpec::Cells::ExampleGroup, :type => :cell

  Cell::Testing.capybara = true if Object.const_defined?(:"Capybara")
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rspec-cells-0.3.4 lib/rspec/cells/example_group.rb
rspec-cells-0.3.3 lib/rspec/cells/example_group.rb