Class: Webspicy::Web::Specification::TestCase

Inherits:
Specification::TestCase show all
Defined in:
lib/webspicy/web/specification/test_case.rb

Instance Attribute Summary

Attributes inherited from Specification::TestCase

#counterexample, #service

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Specification::TestCase

#assert, #bind, #counterexample?, #description, #example?, #expected, #expected_error, #has_assertions?, #has_expected_error?, info, #initialize, #input, #metadata, #mutate, #seeds, #specification, #tags, #to_s

Methods included from Support::DataObject

#initialize, #method_missing, #to_info

Constructor Details

This class inherits a constructor from Webspicy::Specification::TestCase

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Webspicy::Support::DataObject

Class Method Details

.v2(info) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/webspicy/web/specification/test_case.rb', line 6

def self.v2(info)
  info = info.dup
  if !info.has_key?(:description) && (info.has_key?(:when) || info.has_key?(:it))
    info[:description] = "when #{info[:when]}" if info.has_key?(:when)
    info[:description] << ", it #{info[:it]}" if info.has_key?(:it)
    info.delete_if{|k,v| k == :when || k == :it }
  end
  if !info.has_key?(:dress_params) && info.has_key?(:validate_input)
    info[:dress_params] = info[:validate_input]
    info.delete(:validate_input)
  end
  if !info.has_key?(:params) && info.has_key?(:input)
    info[:params] = info[:input]
    info.delete(:input)
  end
  new(info)
end

Instance Method Details

#bodyObject



37
38
39
# File 'lib/webspicy/web/specification/test_case.rb', line 37

def body
  @raw[:body]
end

#dress_paramsObject Also known as: dress_params?



28
29
30
# File 'lib/webspicy/web/specification/test_case.rb', line 28

def dress_params
  @raw.fetch(:dress_params){ true }
end

#expected_content_typeObject



49
50
51
# File 'lib/webspicy/web/specification/test_case.rb', line 49

def expected_content_type
  expected[:content_type]
end

#expected_headersObject



70
71
72
# File 'lib/webspicy/web/specification/test_case.rb', line 70

def expected_headers
  expected[:headers] || {}
end

#expected_statusObject



53
54
55
# File 'lib/webspicy/web/specification/test_case.rb', line 53

def expected_status
  expected[:status]
end

#file_uploadObject



41
42
43
# File 'lib/webspicy/web/specification/test_case.rb', line 41

def file_upload
  @raw[:file_upload]
end

#has_expected_headers?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/webspicy/web/specification/test_case.rb', line 74

def has_expected_headers?
  !expected_headers.empty?
end

#has_expected_status?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/webspicy/web/specification/test_case.rb', line 61

def has_expected_status?
  not expected[:status].nil?
end

#headersObject



24
25
26
# File 'lib/webspicy/web/specification/test_case.rb', line 24

def headers
  @raw[:headers] ||= {}
end

#is_expected_status?(status) ⇒ Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/webspicy/web/specification/test_case.rb', line 57

def is_expected_status?(status)
  expected_status === status
end

#is_redirect_expected_status?Boolean

Returns:

  • (Boolean)


65
66
67
68
# File 'lib/webspicy/web/specification/test_case.rb', line 65

def is_redirect_expected_status?
  start = expected_status.to_int
  start >= 300 && start < 400
end

#located_file_uploadObject



45
46
47
# File 'lib/webspicy/web/specification/test_case.rb', line 45

def located_file_upload
  file_upload ? file_upload.locate(specification) : nil
end

#paramsObject



33
34
35
# File 'lib/webspicy/web/specification/test_case.rb', line 33

def params
  @raw[:params] || {}
end

#to_v2Object



78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/webspicy/web/specification/test_case.rb', line 78

def to_v2
  info = to_info
  info = info.merge({
    validate_input: !!info[:dress_params],
    input: info[:params] || {},
  }).delete_if{|k,v| k == :dress_params || k == :params }
  if info[:description] =~ /^when (.*?), it (.*)$/
    info[:when] = $1
    info[:it] = $2
    info.delete(:description)
  end
  info
end