Sha256: c34a98f850691e3f6e12d706d737d4dcfab2a68274f28cede1c5ced3e88ea414

Contents?: true

Size: 1.35 KB

Versions: 3

Compression:

Stored size: 1.35 KB

Contents

require 'fitting/report/action'

module Fitting
  module Report
    class Actions
      def initialize(prefix, tomogram_json_path)
        actions = Tomograph::Tomogram.new(
            prefix: prefix,
            tomogram_json_path: tomogram_json_path
        )
        @actions = []
        actions.to_a.map do |action|
          @actions.push(Fitting::Report::Action.new(action))
        end
      end

      def to_a
        @actions
      end

      def join(tests)
        tests.to_a.map do |test|
          if is_there_a_suitable_action?(test)
            cram_into_the_appropriate_action(test)
            test.mark_action
          end
        end
      end

      def is_there_a_suitable_action?(test)
        @actions.map do |action|
          return true if test.method == action.method && action.path_match(test.path)
        end

        false
      end

      def cram_into_the_appropriate_action(test)
        @actions.map do |action|
          if test.method == action.method && action.path_match(test.path)
            action.add_test(test)
            return
          end
        end
      end

      def details(prefix)
        {
            tests_without_actions: prefix.tests.without_actions,
            actions_details: @actions.map { |a| {method: a.method, path: a.path, tests_size: a.tests.size, responses: a.details} }
        }
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fitting-2.15.0 lib/fitting/report/actions.rb
fitting-2.14.1 lib/fitting/report/actions.rb
fitting-2.14.0 lib/fitting/report/actions.rb