restspec-rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +35 -0
  3. data/Gemfile +14 -0
  4. data/Gemfile.lock +158 -0
  5. data/LICENSE +22 -0
  6. data/README.md +48 -0
  7. data/Rakefile +1 -0
  8. data/dummy/.gitignore +16 -0
  9. data/dummy/.rspec +2 -0
  10. data/dummy/README.rdoc +28 -0
  11. data/dummy/Rakefile +6 -0
  12. data/dummy/app/assets/images/.keep +0 -0
  13. data/dummy/app/assets/javascripts/application.js +16 -0
  14. data/dummy/app/assets/stylesheets/application.css +15 -0
  15. data/dummy/app/controllers/application_controller.rb +5 -0
  16. data/dummy/app/controllers/concerns/.keep +0 -0
  17. data/dummy/app/helpers/application_helper.rb +2 -0
  18. data/dummy/app/mailers/.keep +0 -0
  19. data/dummy/app/models/.keep +0 -0
  20. data/dummy/app/models/concerns/.keep +0 -0
  21. data/dummy/app/views/layouts/application.html.erb +14 -0
  22. data/dummy/bin/bundle +3 -0
  23. data/dummy/bin/rails +8 -0
  24. data/dummy/bin/rake +8 -0
  25. data/dummy/bin/spring +18 -0
  26. data/dummy/config.ru +4 -0
  27. data/dummy/config/application.rb +31 -0
  28. data/dummy/config/boot.rb +4 -0
  29. data/dummy/config/database.yml +25 -0
  30. data/dummy/config/environment.rb +5 -0
  31. data/dummy/config/environments/development.rb +37 -0
  32. data/dummy/config/environments/production.rb +78 -0
  33. data/dummy/config/environments/test.rb +39 -0
  34. data/dummy/config/initializers/assets.rb +8 -0
  35. data/dummy/config/initializers/backtrace_silencers.rb +7 -0
  36. data/dummy/config/initializers/cookies_serializer.rb +3 -0
  37. data/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  38. data/dummy/config/initializers/inflections.rb +16 -0
  39. data/dummy/config/initializers/mime_types.rb +4 -0
  40. data/dummy/config/initializers/session_store.rb +3 -0
  41. data/dummy/config/initializers/wrap_parameters.rb +14 -0
  42. data/dummy/config/locales/en.yml +23 -0
  43. data/dummy/config/routes.rb +56 -0
  44. data/dummy/config/secrets.yml +22 -0
  45. data/dummy/db/schema.rb +16 -0
  46. data/dummy/db/seeds.rb +7 -0
  47. data/dummy/lib/assets/.keep +0 -0
  48. data/dummy/lib/tasks/.keep +0 -0
  49. data/dummy/log/.keep +0 -0
  50. data/dummy/public/404.html +67 -0
  51. data/dummy/public/422.html +67 -0
  52. data/dummy/public/500.html +66 -0
  53. data/dummy/public/favicon.ico +0 -0
  54. data/dummy/public/robots.txt +5 -0
  55. data/dummy/spec/api/restspec/endpoints.rb +5 -0
  56. data/dummy/spec/api/restspec/requirements.rb +0 -0
  57. data/dummy/spec/api/restspec/restspec_config.rb +13 -0
  58. data/dummy/spec/api/restspec/schemas.rb +3 -0
  59. data/dummy/spec/api/secrets_spec.rb +9 -0
  60. data/dummy/spec/rails_helper.rb +58 -0
  61. data/dummy/spec/spec_helper.rb +85 -0
  62. data/dummy/vendor/assets/javascripts/.keep +0 -0
  63. data/dummy/vendor/assets/stylesheets/.keep +0 -0
  64. data/lib/generators/restspec/install_generator.rb +41 -0
  65. data/lib/generators/restspec/templates/restspec_config.rb +13 -0
  66. data/lib/restspec-rails.rb +12 -0
  67. data/lib/restspec/rails/network_adapter.rb +24 -0
  68. data/lib/restspec/rails/version.rb +5 -0
  69. data/restspec-rails.gemspec +28 -0
  70. metadata +186 -0
@@ -0,0 +1,7 @@
1
+ # This file should contain all the record creation needed to seed the database with its default values.
2
+ # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
3
+ #
4
+ # Examples:
5
+ #
6
+ # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
7
+ # Mayor.create(name: 'Emanuel', city: cities.first)
File without changes
File without changes
File without changes
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/404.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The page you were looking for doesn't exist.</h1>
62
+ <p>You may have mistyped the address or the page may have moved.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/422.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The change you wanted was rejected.</h1>
62
+ <p>Maybe you tried to change something you didn't have access to.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,66 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/500.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>We're sorry, but something went wrong.</h1>
62
+ </div>
63
+ <p>If you are the application owner check the logs for more information.</p>
64
+ </div>
65
+ </body>
66
+ </html>
File without changes
@@ -0,0 +1,5 @@
1
+ # See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
2
+ #
3
+ # To ban all spiders from the entire site uncomment the next two lines:
4
+ # User-agent: *
5
+ # Disallow: /
@@ -0,0 +1,5 @@
1
+ resource :secrets do
2
+ collection do
3
+ post :create
4
+ end
5
+ end
@@ -0,0 +1,13 @@
1
+ Restspec.configure do |config|
2
+ config.schema_definition = "#{File.dirname __FILE__}/schemas.rb"
3
+ config.endpoints_definition = "#{File.dirname __FILE__}/endpoints.rb"
4
+ config.requirements_definition = "#{File.dirname __FILE__}/requirements.rb"
5
+
6
+ # This is important for Rails :)
7
+ config.request.network_adapter = ->{ Restspec::Rails::NetworkAdapter.new }
8
+
9
+ #
10
+ # => to add custom headers, use config.request.headers like this:
11
+ #
12
+ # config.request.headers['AUTHORIZATION'] = "Token token=\"#{config.custom.api_key}\""
13
+ end
@@ -0,0 +1,3 @@
1
+ schema :secret do
2
+ attribute :message, string
3
+ end
@@ -0,0 +1,9 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe :secrets, :type => :api do
4
+ endpoint 'secrets/create' do
5
+ test do
6
+ it { should have_status(201) }
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,58 @@
1
+ require 'restspec'
2
+
3
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
4
+ ENV["RAILS_ENV"] ||= 'test'
5
+ require 'spec_helper'
6
+ require File.expand_path("../../config/environment", __FILE__)
7
+ require 'rspec/rails'
8
+ # Add additional requires below this line. Rails is not loaded until this point!
9
+
10
+ # Requires supporting ruby files with custom matchers and macros, etc, in
11
+ # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
12
+ # run as spec files by default. This means that files in spec/support that end
13
+ # in _spec.rb will both be required and run as specs, causing the specs to be
14
+ # run twice. It is recommended that you do not name files matching this glob to
15
+ # end with _spec.rb. You can configure this pattern with the --pattern
16
+ # option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
17
+ #
18
+ # The following line is provided for convenience purposes. It has the downside
19
+ # of increasing the boot-up time by auto-requiring all files in the support
20
+ # directory. Alternatively, in the individual `*_spec.rb` files, manually
21
+ # require only the support files necessary.
22
+ #
23
+ # Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
24
+
25
+ # Checks for pending migrations before tests are run.
26
+ # If you are not using ActiveRecord, you can remove this line.
27
+ ActiveRecord::Migration.maintain_test_schema!
28
+
29
+ RSpec.configure do |config|
30
+ # Restspec helpers and macros
31
+ config.include Restspec::RSpec::ApiHelpers, :type => :api
32
+ config.extend Restspec::RSpec::ApiMacros, :type => :api
33
+
34
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
35
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
36
+
37
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
38
+ # examples within a transaction, remove the following line or assign false
39
+ # instead of true.
40
+ config.use_transactional_fixtures = true
41
+
42
+ # RSpec Rails can automatically mix in different behaviours to your tests
43
+ # based on their file location, for example enabling you to call `get` and
44
+ # `post` in specs under `spec/controllers`.
45
+ #
46
+ # You can disable this behaviour by removing the line below, and instead
47
+ # explicitly tag your specs with their type, e.g.:
48
+ #
49
+ # RSpec.describe UsersController, :type => :controller do
50
+ # # ...
51
+ # end
52
+ #
53
+ # The different available types are documented in the features, such as in
54
+ # https://relishapp.com/rspec/rspec-rails/docs
55
+ config.infer_spec_type_from_file_location!
56
+ end
57
+
58
+ require_relative './api/restspec/restspec_config'
@@ -0,0 +1,85 @@
1
+ # This file was generated by the `rails generate rspec:install` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
4
+ # file to always be loaded, without a need to explicitly require it in any files.
5
+ #
6
+ # Given that it is always loaded, you are encouraged to keep this file as
7
+ # light-weight as possible. Requiring heavyweight dependencies from this file
8
+ # will add to the boot time of your test suite on EVERY test run, even for an
9
+ # individual file that may not need all of that loaded. Instead, consider making
10
+ # a separate helper file that requires the additional dependencies and performs
11
+ # the additional setup, and require it from the spec files that actually need it.
12
+ #
13
+ # The `.rspec` file also contains a few flags that are not defaults but that
14
+ # users commonly want.
15
+ #
16
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
17
+ RSpec.configure do |config|
18
+ # rspec-expectations config goes here. You can use an alternate
19
+ # assertion/expectation library such as wrong or the stdlib/minitest
20
+ # assertions if you prefer.
21
+ config.expect_with :rspec do |expectations|
22
+ # This option will default to `true` in RSpec 4. It makes the `description`
23
+ # and `failure_message` of custom matchers include text for helper methods
24
+ # defined using `chain`, e.g.:
25
+ # be_bigger_than(2).and_smaller_than(4).description
26
+ # # => "be bigger than 2 and smaller than 4"
27
+ # ...rather than:
28
+ # # => "be bigger than 2"
29
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
30
+ end
31
+
32
+ # rspec-mocks config goes here. You can use an alternate test double
33
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
34
+ config.mock_with :rspec do |mocks|
35
+ # Prevents you from mocking or stubbing a method that does not exist on
36
+ # a real object. This is generally recommended, and will default to
37
+ # `true` in RSpec 4.
38
+ mocks.verify_partial_doubles = true
39
+ end
40
+
41
+ # The settings below are suggested to provide a good initial experience
42
+ # with RSpec, but feel free to customize to your heart's content.
43
+ =begin
44
+ # These two settings work together to allow you to limit a spec run
45
+ # to individual examples or groups you care about by tagging them with
46
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
47
+ # get run.
48
+ config.filter_run :focus
49
+ config.run_all_when_everything_filtered = true
50
+
51
+ # Limits the available syntax to the non-monkey patched syntax that is recommended.
52
+ # For more details, see:
53
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
54
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
55
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
56
+ config.disable_monkey_patching!
57
+
58
+ # Many RSpec users commonly either run the entire suite or an individual
59
+ # file, and it's useful to allow more verbose output when running an
60
+ # individual spec file.
61
+ if config.files_to_run.one?
62
+ # Use the documentation formatter for detailed output,
63
+ # unless a formatter has already been configured
64
+ # (e.g. via a command-line flag).
65
+ config.default_formatter = 'doc'
66
+ end
67
+
68
+ # Print the 10 slowest examples and example groups at the
69
+ # end of the spec run, to help surface which specs are running
70
+ # particularly slow.
71
+ config.profile_examples = 10
72
+
73
+ # Run specs in random order to surface order dependencies. If you find an
74
+ # order dependency and want to debug it, you can fix the order by providing
75
+ # the seed, which is printed after each run.
76
+ # --seed 1234
77
+ config.order = :random
78
+
79
+ # Seed global randomization in this process using the `--seed` CLI option.
80
+ # Setting this allows you to use `--seed` to deterministically reproduce
81
+ # test failures related to randomization by passing the same `--seed` value
82
+ # as the one that triggered the failure.
83
+ Kernel.srand config.seed
84
+ =end
85
+ end
File without changes
File without changes
@@ -0,0 +1,41 @@
1
+ require 'rails/generators'
2
+
3
+ module Restspec
4
+ class InstallGenerator < ::Rails::Generators::Base
5
+ desc "Install files for Restspec"
6
+ source_root File.expand_path('../templates', __FILE__)
7
+
8
+ def ensure_api_restspec_folder
9
+ empty_directory "spec/api"
10
+ empty_directory "spec/api/restspec"
11
+ end
12
+
13
+ def create_config_file
14
+ template 'restspec_config.rb', "spec/api/restspec/restspec_config.rb"
15
+ end
16
+
17
+ def create_api_dsl_files
18
+ create_file "spec/api/restspec/endpoints.rb"
19
+ create_file "spec/api/restspec/schemas.rb"
20
+ create_file "spec/api/restspec/requirements.rb"
21
+ end
22
+
23
+ def modify_spec_helper
24
+ prepend_to_file rspec_helper_file, "require 'restspec'\n\n"
25
+ gsub_file rspec_helper_file, "RSpec.configure do |config|" do
26
+ "RSpec.configure do |config|
27
+ # Restspec helpers and macros
28
+ config.include Restspec::RSpec::ApiHelpers, :type => :api
29
+ config.extend Restspec::RSpec::ApiMacros, :type => :api
30
+ "
31
+ end
32
+ append_to_file rspec_helper_file, "\nrequire_relative './api/restspec/restspec_config'\n"
33
+ end
34
+
35
+ private
36
+
37
+ def rspec_helper_file
38
+ 'spec/rails_helper.rb'
39
+ end
40
+ end
41
+ end