rspec-endpoint 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f06acdfcb2908e50c524a5521ac4991c2044f186
4
+ data.tar.gz: 1c065856da5d223c66a2ab5a45c07e8b7dcde2ad
5
+ SHA512:
6
+ metadata.gz: cab8b9d7b80df02837414d2ad932c3d65177bd1d0c59e88337ac30aecef6d944cf2042f77543a824aa882586734beb19cbbe3702457e02f103ce82902d99ef9c
7
+ data.tar.gz: b086a7287608235954bd223190ef7cc0564b17c51dffbcb4b348729e14cfadc38a05b40505d2b77f98dbe294e5b20e9764fa78795d9e64bba6007f3b6d17949b
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # Rspec::Endpoint
2
+
3
+ RSpec::Endpoint provides the `endpoint` method as a helper to test HTTP requests. It parses and replaces the description with the informed params.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem "rspec-endpoint"
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install rspec-endpoint
20
+
21
+ And require it as:
22
+
23
+ ```ruby
24
+ require "rspec/endpoint"
25
+ ```
26
+
27
+ ## Example
28
+
29
+ ```ruby
30
+ RSpec.descripe UserApi do
31
+ endpoint "GET /users/:user_id" do
32
+ let(:user_id) { 10 }
33
+
34
+ it { expect(path).to eq "/users/10" }
35
+ it { expect(params).to eq user_id: 10 }
36
+ end
37
+ end
38
+ ```
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,35 @@
1
+ require "rspec/endpoint/version"
2
+
3
+ module RSpec
4
+ module Endpoint
5
+ def endpoint(description, metadata = {}, &block)
6
+ method, path = description.split(" ")
7
+ method = method.downcase
8
+
9
+ methods = %w(get post put delete patch head options)
10
+ fail "Invalid method #{method}. Valid options: #{methods}" unless methods.include? method.downcase
11
+
12
+ segments = path.split("/")
13
+
14
+ path_params = segments.select { |segment| segment.start_with?(":") }.map { |segment| segment[1..-1] }
15
+
16
+ describe(description, metadata) do
17
+ let(:path) { segments.map { |seg| seg.start_with?(":") ? send(seg[1..-1]) : seg }.join("/") }
18
+ let(:params) { path_params.reduce({}) { |params, param| params.merge(param.to_sym => send(param)) } }
19
+
20
+ path_params.each { |param| let(param.to_sym) { send(param.to_sym) } }
21
+
22
+ subject { send(method.to_sym, params) }
23
+
24
+ class_eval(&block)
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+ RSpec.configure do |rspec|
31
+ rspec.extend RSpec::Endpoint
32
+ rspec.backtrace_exclusion_patterns << %r(/lib/rspec/endpoint)
33
+ end
34
+
35
+ RSpec::SharedContext.send(:include, RSpec::Endpoint)
@@ -0,0 +1,5 @@
1
+ module RSpec
2
+ module Endpoint
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rspec/endpoint/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rspec-endpoint"
8
+ spec.version = RSpec::Endpoint::VERSION
9
+ spec.authors = ["Rodrigo Navarro"]
10
+ spec.email = ["rnavarro@rnavarro.com.br"]
11
+
12
+ spec.summary = "Simple syntax additions to ease API request tests with RSpec"
13
+ spec.description = %q{RSpec::Endpoint provides the `endpoint` method as a helper to test HTTP requests. It parses and replaces the description with the informed params.}
14
+ spec.homepage = "https://github.com/reu/rspec-endpoint"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_runtime_dependency "rspec-core", ">= 3.0.0"
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.9"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec-endpoint
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Rodrigo Navarro
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec-core
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 3.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 3.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.9'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: RSpec::Endpoint provides the `endpoint` method as a helper to test HTTP
56
+ requests. It parses and replaces the description with the informed params.
57
+ email:
58
+ - rnavarro@rnavarro.com.br
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".travis.yml"
66
+ - Gemfile
67
+ - README.md
68
+ - Rakefile
69
+ - lib/rspec/endpoint.rb
70
+ - lib/rspec/endpoint/version.rb
71
+ - rspec-endpoint.gemspec
72
+ homepage: https://github.com/reu/rspec-endpoint
73
+ licenses: []
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.4.5
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: Simple syntax additions to ease API request tests with RSpec
95
+ test_files: []