rspec-rails-swagger 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ee3d27df0e7ec24ced93bd4a298f649b86715b12
4
- data.tar.gz: 0e96a4167c43c555b94b81d93901939311e0dd98
3
+ metadata.gz: b786f25e06ff3d37c343ea9a9156d215de7a75e3
4
+ data.tar.gz: 4d35f9fcde88c3434270c79ddb41db882a6827e5
5
5
  SHA512:
6
- metadata.gz: 217c592d0a3331819d7264a7356885ec3e69d8cc075aa7a6f98e524f5dcf96466adefefd16214772abdbd42a494f5df78d4bc3e6cc1482f86c797d3f12bc0c35
7
- data.tar.gz: d9b5651ac3f9c4a76c09ca9efce6e0f671f4c5264c79dfaa0356ada5e7f13c18cdf1336352a7e8f0a9a70fb45cd427f1fd591015d755c63442c85d359f86eb66
6
+ metadata.gz: 301367639404276196630c3dd68748943e228664851d0d4e53695835e640d461c6a2ad227c14d9dee4ec097122ab261ce8afde0078b93bf7b6581973e954f980
7
+ data.tar.gz: b57370b15e66decde9ef4b19f20fe0877da65ed2fd76cc50bdab08c725106f2f8b69107542bce1e989064e7f36d56dc49730601f836804c3f49486855994ba19
@@ -10,6 +10,14 @@ module RSpec
10
10
  module Rails
11
11
  module Swagger
12
12
  initialize_configuration RSpec.configuration
13
+
14
+ if defined?(::Rails)
15
+ class Railtie < ::Rails::Railtie
16
+ rake_tasks do
17
+ load 'rspec/rails/swagger/tasks/swagger.rake'
18
+ end
19
+ end
20
+ end
13
21
  end
14
22
  end
15
23
  end
@@ -1,10 +1,13 @@
1
- require 'rspec/core/formatters/base_text_formatter'
1
+ RSpec::Support.require_rspec_core "formatters/base_text_formatter"
2
+ RSpec::Support.require_rspec_core "formatters/console_codes"
2
3
 
3
4
  module RSpec
4
5
  module Rails
5
6
  module Swagger
6
7
  class Formatter < RSpec::Core::Formatters::BaseTextFormatter
7
- RSpec::Core::Formatters.register self, :example_finished, :close
8
+ RSpec::Core::Formatters.register self, :example_group_started,
9
+ :example_passed, :example_pending, :example_failed, :example_finished,
10
+ :close
8
11
 
9
12
  def documents
10
13
  # We don't try to load the docs in `initalize` because when running
@@ -13,22 +16,58 @@ module RSpec
13
16
  @documents ||= ::RSpec.configuration.swagger_docs
14
17
  end
15
18
 
19
+ def example_group_started(notification)
20
+ output.print *group_output(notification)
21
+ end
22
+
23
+ def example_passed(notification)
24
+ output.print RSpec::Core::Formatters::ConsoleCodes.wrap(example_output(notification), :success)
25
+ end
26
+
27
+ def example_pending(notification)
28
+ output.print RSpec::Core::Formatters::ConsoleCodes.wrap(example_output(notification), :pending)
29
+ end
30
+
31
+ def example_failed(notification)
32
+ output.print RSpec::Core::Formatters::ConsoleCodes.wrap(example_output(notification), :failure)
33
+ end
34
+
16
35
  def example_finished(notification)
17
- metadata = notification.example.metadata
36
+ metadata = notification.example.metadata
18
37
  return unless metadata[:swagger_object] == :response
19
38
 
20
- # metadata.each do |k, v|
21
- # puts "#{k}\t#{v}" if k.to_s.starts_with?("swagger")
22
- # end
23
-
39
+ # Then add everything to the document
24
40
  document = document_for(metadata[:swagger_document])
25
41
  path_item = path_item_for(document, metadata[:swagger_path_item])
26
42
  operation = operation_for(path_item, metadata[:swagger_operation])
27
- response_for(operation, metadata[:swagger_response])
43
+ response = response_for(operation, metadata[:swagger_response])
28
44
  end
29
45
 
30
46
  def close(_notification)
31
47
  documents.each{|k, v| write_json(k, v)}
48
+
49
+ self
50
+ end
51
+
52
+ private
53
+
54
+ def group_output(notification)
55
+ metadata = notification.group.metadata
56
+
57
+ # This is a little odd because I didn't want to split the logic across
58
+ # a start and end method. Instead we just start a new line for each
59
+ # path and operation and just let the status codes pile up on the end.
60
+ # There's probably a better way that doesn't have the initial newline.
61
+ case metadata[:swagger_object]
62
+ when :path_item
63
+ ["\n", metadata[:swagger_path_item][:path]]
64
+ when :operation
65
+ ["\n ", metadata[:swagger_operation][:method].to_s, "\t"]
66
+ end
67
+ end
68
+
69
+ def example_output(notification)
70
+ " #{notification.example.metadata[:swagger_response][:status_code]}"
32
71
  end
33
72
 
34
73
  def write_json(name, document)
@@ -91,9 +130,9 @@ module RSpec
91
130
  end
92
131
 
93
132
  def prepare_examples(examples)
94
- if examples["application/json"].present?
133
+ if examples['application/json'].kind_of? String
95
134
  begin
96
- examples["application/json"] = JSON.parse(examples["application/json"])
135
+ examples['application/json'] = JSON.parse(examples['application/json'])
97
136
  rescue JSON::ParserError
98
137
  end
99
138
  end
@@ -0,0 +1,7 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ desc "Regenerate Swagger docs"
4
+ RSpec::Core::RakeTask.new(:swagger) do |t|
5
+ t.verbose = false
6
+ t.rspec_opts = "-f RSpec::Rails::Swagger::Formatter --order defined -t swagger_object"
7
+ end
@@ -3,7 +3,7 @@ module RSpec
3
3
  # Version information for RSpec Swagger.
4
4
  module Swagger
5
5
  module Version
6
- STRING = '0.1.0'
6
+ STRING = '0.1.1'
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-rails-swagger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - andrew morton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-26 00:00:00.000000000 Z
11
+ date: 2016-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -50,6 +50,7 @@ files:
50
50
  - lib/rspec/rails/swagger/formatter.rb
51
51
  - lib/rspec/rails/swagger/helpers.rb
52
52
  - lib/rspec/rails/swagger/request_builder.rb
53
+ - lib/rspec/rails/swagger/tasks/swagger.rake
53
54
  - lib/rspec/rails/swagger/version.rb
54
55
  homepage: https://github.com/drewish/rspec-rails-swagger
55
56
  licenses: