webspicy 0.20.2 → 0.20.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/bin/webspicy +3 -4
  3. data/lib/finitio/webspicy/shared.fio +10 -0
  4. data/lib/webspicy.rb +22 -53
  5. data/lib/webspicy/configuration.rb +17 -0
  6. data/lib/webspicy/configuration/scope.rb +3 -2
  7. data/lib/webspicy/configuration/single_url.rb +35 -25
  8. data/lib/webspicy/configuration/single_yml_file.rb +7 -2
  9. data/lib/webspicy/specification.rb +0 -55
  10. data/lib/webspicy/specification/post/missing_condition_impl.rb +2 -2
  11. data/lib/webspicy/specification/post/unexpected_condition_impl.rb +2 -2
  12. data/lib/webspicy/specification/service.rb +1 -5
  13. data/lib/webspicy/specification/test_case.rb +0 -49
  14. data/lib/webspicy/support/colorize.rb +7 -1
  15. data/lib/webspicy/tester.rb +15 -19
  16. data/lib/webspicy/tester/fakesmtp.rb +1 -1
  17. data/lib/webspicy/tester/fakesmtp/email.rb +13 -0
  18. data/lib/webspicy/tester/reporter.rb +5 -0
  19. data/lib/webspicy/tester/reporter/documentation.rb +30 -8
  20. data/lib/webspicy/tester/reporter/error_count.rb +11 -7
  21. data/lib/webspicy/tester/reporter/file_progress.rb +2 -2
  22. data/lib/webspicy/tester/reporter/file_summary.rb +2 -2
  23. data/lib/webspicy/tester/reporter/progress.rb +4 -4
  24. data/lib/webspicy/tester/reporter/summary.rb +8 -7
  25. data/lib/webspicy/tester/result/errcondition_met.rb +1 -3
  26. data/lib/webspicy/tester/result/postcondition_met.rb +1 -3
  27. data/lib/webspicy/version.rb +1 -1
  28. data/lib/webspicy/web.rb +46 -0
  29. data/lib/webspicy/{formaldoc.fio → web/formaldoc.fio} +5 -13
  30. data/lib/webspicy/web/specification.rb +68 -0
  31. data/lib/webspicy/web/specification/file_upload.rb +39 -0
  32. data/lib/webspicy/web/specification/service.rb +13 -0
  33. data/lib/webspicy/web/specification/test_case.rb +58 -0
  34. data/spec/unit/configuration/scope/test_expand_example.rb +11 -5
  35. data/spec/unit/specification/pre/test_global_request_headers.rb +3 -3
  36. data/spec/unit/specification/service/test_dress_params.rb +2 -2
  37. data/spec/unit/test_configuration.rb +1 -0
  38. data/spec/unit/tester/fakesmtp/test_email.rb +93 -0
  39. data/spec/unit/web/specification/test_instantiate_url.rb +36 -0
  40. data/spec/unit/web/specification/test_url_placeholders.rb +23 -0
  41. data/tasks/test.rake +2 -1
  42. metadata +15 -10
  43. data/lib/webspicy/specification/file_upload.rb +0 -37
  44. data/spec/unit/specification/test_instantiate_url.rb +0 -34
  45. data/spec/unit/specification/test_url_placeholders.rb +0 -21
@@ -43,10 +43,6 @@ module Webspicy
43
43
  @raw[:seeds]
44
44
  end
45
45
 
46
- def headers
47
- @raw[:headers] ||= {}
48
- end
49
-
50
46
  def metadata
51
47
  @raw[:metadata] ||= {}
52
48
  end
@@ -55,47 +51,10 @@ module Webspicy
55
51
  @raw[:tags] ||= []
56
52
  end
57
53
 
58
- def dress_params
59
- @raw.fetch(:dress_params){ true }
60
- end
61
- alias :dress_params? :dress_params
62
-
63
- def params
64
- @raw[:params] || {}
65
- end
66
-
67
- def body
68
- @raw[:body]
69
- end
70
-
71
- def file_upload
72
- @raw[:file_upload]
73
- end
74
-
75
- def located_file_upload
76
- file_upload ? file_upload.locate(specification) : nil
77
- end
78
-
79
54
  def expected
80
55
  @raw[:expected] || {}
81
56
  end
82
57
 
83
- def expected_content_type
84
- expected[:content_type]
85
- end
86
-
87
- def expected_status
88
- expected[:status]
89
- end
90
-
91
- def is_expected_status?(status)
92
- expected_status === status
93
- end
94
-
95
- def has_expected_status?
96
- not expected[:status].nil?
97
- end
98
-
99
58
  def expected_error
100
59
  expected[:error]
101
60
  end
@@ -104,14 +63,6 @@ module Webspicy
104
63
  !expected_error.nil?
105
64
  end
106
65
 
107
- def expected_headers
108
- expected[:headers] || {}
109
- end
110
-
111
- def has_expected_headers?
112
- !expected_headers.empty?
113
- end
114
-
115
66
  def assert
116
67
  @raw[:assert] || []
117
68
  end
@@ -3,11 +3,17 @@ module Webspicy
3
3
  module Colorize
4
4
 
5
5
  def colorize(str, kind, config = nil)
6
+ return str if config && !config.colorize
6
7
  color = (config || self.config).colors[kind]
7
- ColorizedString[str].colorize(color)
8
+ Paint[str, color]
8
9
  end
9
10
  module_function :colorize
10
11
 
12
+ def colorize_section(str, cfg = nil)
13
+ colorize(str, :section, cfg)
14
+ end
15
+ module_function :colorize_section
16
+
11
17
  def colorize_highlight(str, cfg = nil)
12
18
  colorize(str, :highlight, cfg)
13
19
  end
@@ -15,7 +15,7 @@ module Webspicy
15
15
  @test_case = nil
16
16
  @invocation = nil
17
17
  @invocation_error = nil
18
- @reporter = default_reporter
18
+ @reporter = @config.reporter
19
19
  end
20
20
  attr_reader :config, :scope, :hooks, :client
21
21
  attr_reader :specification, :spec_file
@@ -31,15 +31,6 @@ module Webspicy
31
31
  config.failfast
32
32
  end
33
33
 
34
- def default_reporter
35
- @reporter = Reporter::Composite.new
36
- #@reporter << Reporter::Progress.new
37
- @reporter << Reporter::Documentation.new
38
- @reporter << Reporter::Exceptions.new
39
- @reporter << Reporter::Summary.new
40
- @reporter << Reporter::ErrorCount.new
41
- end
42
-
43
34
  def call
44
35
  reporter.init(self)
45
36
  begin
@@ -50,6 +41,11 @@ module Webspicy
50
41
  reporter.find(Reporter::ErrorCount).report
51
42
  end
52
43
 
44
+ def call!
45
+ res = call
46
+ abort("KO") unless res == 0
47
+ end
48
+
53
49
  def find_and_call(method, url, mutation)
54
50
  unless tc = scope.find_test_case(method, url)
55
51
  raise Error, "No such service `#{method} #{url}`"
@@ -73,19 +69,15 @@ module Webspicy
73
69
  @scope = scope
74
70
  @hooks = Support::Hooks.for(scope.config)
75
71
  @client = scope.get_client
76
- reporter.before_all
77
- @hooks.fire_before_all(self)
78
- reporter.before_all_done
79
- reporter.before_scope
80
72
  run_scope
81
- reporter.scope_done
82
- reporter.after_all
83
- @hooks.fire_after_all(self)
84
- reporter.after_all_done
85
73
  end
86
74
  end
87
75
 
88
76
  def run_scope
77
+ reporter.before_all
78
+ hooks.fire_before_all(self)
79
+ reporter.before_all_done
80
+ reporter.before_scope
89
81
  scope.each_specification_file do |spec_file|
90
82
  @specification = load_specification(spec_file)
91
83
  if @specification
@@ -97,12 +89,16 @@ module Webspicy
97
89
  raise FailFast
98
90
  end
99
91
  end
92
+ reporter.scope_done
93
+ reporter.after_all
94
+ hooks.fire_after_all(self)
95
+ reporter.after_all_done
100
96
  end
101
97
 
102
98
  def load_specification(spec_file)
103
99
  @spec_file = spec_file
104
100
  reporter.before_spec_file
105
- Webspicy.specification(spec_file.load, spec_file, scope)
101
+ config.factory.specification(spec_file.load, spec_file, scope)
106
102
  rescue *PASSTHROUGH_EXCEPTIONS
107
103
  raise
108
104
  rescue Exception => e
@@ -30,7 +30,7 @@ module Webspicy
30
30
  end
31
31
 
32
32
  def last_email
33
- emails.last
33
+ emails.first
34
34
  end
35
35
 
36
36
  end # class Fakesmtp
@@ -21,6 +21,19 @@ module Webspicy
21
21
  .map{|h| h["line"][/To:\s*(.*)$/, 1] }
22
22
  end
23
23
 
24
+ def reply_to
25
+ @reply_to ||= data["headerLines"]
26
+ .select{|h| h["key"] == "reply-to" }
27
+ .map{|h| h["line"][/Reply-To:\s*(.*)$/, 1] }
28
+ end
29
+
30
+ def subject
31
+ @subject ||= data["headerLines"]
32
+ .select{|h| h["key"] == "subject" }
33
+ .map{|h| h["line"][/Subject:\s*(.*)$/, 1] }
34
+ .first
35
+ end
36
+
24
37
  end # class Email
25
38
  end # class Fakesmtp
26
39
  end # class Tester
@@ -66,6 +66,11 @@ module Webspicy
66
66
  }
67
67
  end
68
68
 
69
+ def find(kind)
70
+ return self if self.is_a?(kind)
71
+ raise "Missing reporter #{kind}"
72
+ end
73
+
69
74
  protected
70
75
 
71
76
  def plural(word, count)
@@ -4,41 +4,63 @@ module Webspicy
4
4
  class Documentation < Reporter
5
5
 
6
6
  module Helpers
7
+ INDENT = " ".freeze
8
+
9
+ def spec_file_line(spec_file)
10
+ path = Path(spec_file).expand_path
11
+ path = path.relative_to(config.folder)
12
+ path = spec_file if path.to_s.start_with?(".")
13
+ colorize_section(">> #{path}", config)
14
+ end
15
+
7
16
  def spec_file_error_line(spec_file, ex)
8
- str = colorize_highlight(spec_file.to_s)
9
- str += "\n " + colorize_error("X #{ex.message}")
17
+ str = ""
18
+ str += colorize_error(INDENT + "X #{ex.message}", config)
10
19
  if ex.root_cause && ex.root_cause != ex
11
- str += "\n " + colorize_error("#{ex.root_cause.message}")
20
+ str += "\n"
21
+ str += INDENT + colorize_error("#{ex.root_cause.message}", config)
12
22
  end
13
23
  str
14
24
  end
15
25
 
16
26
  def service_line(service, test_case)
17
- str = service.to_s + ", " + test_case.to_s
18
- str = colorize_highlight(str)
27
+ str = "#{service}, #{test_case}"
28
+ str = colorize_highlight(str, config)
19
29
  end
20
30
 
21
31
  def check_success_line(check)
22
- " " + colorize_success("v") + " " + check.behavior
32
+ INDENT + colorize_success("v " + check.behavior, config)
23
33
  end
24
34
 
25
35
  def check_failure_line(check, ex)
26
- " " + colorize_error("F " + ex.message)
36
+ INDENT + colorize_error("F " + ex.message, config)
27
37
  end
28
38
 
29
39
  def check_error_line(check, ex)
30
- " " + colorize_error("E " + ex.message)
40
+ INDENT + colorize_error("E " + ex.message, config)
31
41
  end
32
42
  end
33
43
  include Helpers
34
44
 
35
45
  def spec_file_error(e)
46
+ io.puts spec_file_line(spec_file)
47
+ io.puts
36
48
  io.puts spec_file_error_line(spec_file, e)
37
49
  io.puts
38
50
  io.flush
39
51
  end
40
52
 
53
+ def before_service
54
+ @spec_file_line_printed = false
55
+ end
56
+
41
57
  def before_test_case
58
+ unless @spec_file_line_printed
59
+ io.puts spec_file_line(spec_file)
60
+ io.puts
61
+ io.flush
62
+ @spec_file_line_printed = true
63
+ end
42
64
  io.puts service_line(service, test_case)
43
65
  io.flush
44
66
  end
@@ -5,18 +5,22 @@ module Webspicy
5
5
 
6
6
  def initialize(*args, &bl)
7
7
  super
8
- @error_count = 0
8
+ @errors = Hash.new{|h,k| 0 }
9
9
  end
10
+ attr_reader :errors
10
11
 
11
- def on_error(*args, &bl)
12
- @error_count += 1
12
+ [
13
+ :spec_file_error,
14
+ :check_error,
15
+ :check_failure
16
+ ].each do |meth|
17
+ define_method(meth) do |*args, &bl|
18
+ @errors[meth] += 1
19
+ end
13
20
  end
14
- alias :spec_file_error :on_error
15
- alias :check_failure :on_error
16
- alias :check_error :on_error
17
21
 
18
22
  def report
19
- @error_count
23
+ @errors.values.inject(0){|memo,x| memo+x }
20
24
  end
21
25
 
22
26
  end # class ErrorCount
@@ -4,12 +4,12 @@ module Webspicy
4
4
  class FileProgress < Reporter
5
5
 
6
6
  def spec_file_error(e)
7
- io.print colorize_error("X")
7
+ io.print colorize_error("X", config)
8
8
  io.flush
9
9
  end
10
10
 
11
11
  def spec_file_done
12
- io.print colorize_success(".")
12
+ io.print colorize_success(".", config)
13
13
  io.flush
14
14
  end
15
15
 
@@ -22,9 +22,9 @@ module Webspicy
22
22
  msg = "#{plural('spec file', spec_files_count)}, "\
23
23
  "#{plural('error', errors_count)}"
24
24
  if success?
25
- msg = colorize_success(msg)
25
+ msg = colorize_success(msg, config)
26
26
  else
27
- msg = colorize_error(msg)
27
+ msg = colorize_error(msg, config)
28
28
  end
29
29
  io.puts(msg)
30
30
  io.puts
@@ -4,16 +4,16 @@ module Webspicy
4
4
  class Progress < Reporter
5
5
 
6
6
  def spec_file_error(e)
7
- io.print colorize_error("X")
7
+ io.print colorize_error("X", config)
8
8
  end
9
9
 
10
10
  def after_each_done
11
11
  if result.success?
12
- io.print colorize_success(".")
12
+ io.print colorize_success(".", config)
13
13
  elsif result.failure?
14
- io.print colorize_error("F")
14
+ io.print colorize_error("F", config)
15
15
  elsif result.error?
16
- io.print colorize_error("E")
16
+ io.print colorize_error("E", config)
17
17
  end
18
18
  io.flush
19
19
  end
@@ -9,18 +9,21 @@ module Webspicy
9
9
  @examples_count = 0
10
10
  @counterexamples_count = 0
11
11
  @assertions_count = 0
12
+ #
13
+ @spec_file_errors_count = 0
12
14
  @errors_count = 0
13
15
  @failures_count = 0
14
16
  end
15
17
  attr_reader :spec_files_count, :examples_count, :counterexamples_count
16
- attr_reader :assertions_count, :errors_count, :failures_count
18
+ attr_reader :assertions_count
19
+ attr_reader :spec_file_errors_count, :errors_count, :failures_count
17
20
 
18
21
  def before_spec_file
19
22
  @spec_files_count += 1
20
23
  end
21
24
 
22
25
  def spec_file_error(e)
23
- @errors_count += 1
26
+ @spec_file_errors_count += 1
24
27
  end
25
28
 
26
29
  def after_each_done
@@ -42,19 +45,17 @@ module Webspicy
42
45
  "#{plural('error', errors_count)}, "\
43
46
  "#{plural('failure', failures_count)}"
44
47
  if success?
45
- msg = colorize_success(msg)
48
+ msg = colorize_success(msg, config)
46
49
  else
47
- msg = colorize_error(msg)
50
+ msg = colorize_error(msg, config)
48
51
  end
49
52
  io.puts(msg)
50
53
  io.puts
51
54
  io.flush
52
55
  end
53
56
 
54
- private
55
-
56
57
  def success?
57
- @errors_count == 0 && @failures_count == 0
58
+ @spec_file_errors_count == 0 && @errors_count == 0 && @failures_count == 0
58
59
  end
59
60
 
60
61
  end # class Summary
@@ -18,9 +18,7 @@ module Webspicy
18
18
  end
19
19
 
20
20
  def call
21
- if err = post.check!
22
- _! err
23
- end
21
+ post.check!
24
22
  end
25
23
 
26
24
  end # class ErrconditionMet
@@ -18,9 +18,7 @@ module Webspicy
18
18
  end
19
19
 
20
20
  def call
21
- if err = post.check!
22
- _! err
23
- end
21
+ post.check!
24
22
  end
25
23
 
26
24
  end # class PostconditionMet
@@ -2,7 +2,7 @@ module Webspicy
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 20
5
- TINY = 2
5
+ TINY = 7
6
6
  end
7
7
  VERSION = "#{Version::MAJOR}.#{Version::MINOR}.#{Version::TINY}"
8
8
  end