Module: Shokkenki::Provider::RSpec::Term::JsonPathsTerm

Defined in:
lib/shokkenki/provider/rspec/term/json_paths_term.rb

Instance Method Summary collapse

Instance Method Details

#verify_within(context) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/shokkenki/provider/rspec/term/json_paths_term.rb', line 8

def verify_within context
  term = self
  context.describe 'json' do
    term.value.each do |json_path, term|
      describe json_path do
        before(:each) do
          original_values = @actual_values
          @actual_values = @actual_values.map do |value|
            begin
              JsonPath.on(value, json_path.to_s)
            rescue Exception => e
              self.send(:fail, "#{e} in JSON #{original_values.join(', ')}")
            end
          end.flatten

          self.send(:fail, "Path \"#{json_path.to_s}\" not found in JSON #{original_values.join(', ')}") if @actual_values.empty?
        end

        term.verify_within self
      end
    end
  end
end