rspec-hanami 0.2.0 → 0.3.0

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
- SHA1:
3
- metadata.gz: fe7810f3f6091b3f84741650bc0b0ed5fc47c6e4
4
- data.tar.gz: e9bcc09993433dc175bb0246e6a1b6e073c99645
2
+ SHA256:
3
+ metadata.gz: 766872a649aa3ae7578e764d28a1ac0c061a33486c061cf63f7ae7ef738c75db
4
+ data.tar.gz: 9c24309c64e920ee42c8847c83849f426db7287d50de42e2f258a4bd41223a6d
5
5
  SHA512:
6
- metadata.gz: b62efc3b5892a5a711c19f4afb5dd2ad7d9de765fd5254fc232f775b63ebfc73f8e32c8dc2037a5f3c55766fcd3a744861416cf3fe673c00054ae048449c4216
7
- data.tar.gz: f55cb79cfe6ed792df926d46369927a8b4a91e37a843dddf9e75c9eeecbb9d2d441d63dff1d26555ff20ee3cda2a50d8d82982cbb0351fa50c931d932d474285
6
+ metadata.gz: 96f50c6b6a140a245ba0e4ca930e0c103d86ef4e6aa8b199ddc2ded81fc1631daa11086f5494af36778b11c3adc05d1a35760f3bce16956e3f5cbb8b4833041b
7
+ data.tar.gz: a9338b35cbf52474c20006785312983dde752e46e16b2c44fcefd4d691bb8a2de42632aff249f185f2aed36ce9ac3f4e0ce318020bb468a759216d791a9e2f31
data/.travis.yml CHANGED
@@ -1,4 +1,21 @@
1
1
  language: ruby
2
+ sudo: false
3
+ cache: bundler
4
+ install: true
5
+ env:
6
+ global:
7
+ - JRUBY_OPTS=--dev
8
+ script:
9
+ - 'if [[ "$TRAVIS_RUBY_VERSION" =~ "jruby" ]]; then rvm get head && rvm reload && rvm use --install $TRAVIS_RUBY_VERSION && gem install bundler; fi'
10
+ - 'bundle install'
2
11
  rvm:
3
- - 2.3.0
4
- before_install: gem install bundler -v 1.11.2
12
+ - 2.3.1
13
+ - jruby-9.0.5.0
14
+ - jruby-head
15
+ - ruby-head
16
+
17
+ matrix:
18
+ allow_failures:
19
+ - rvm: ruby-head
20
+ - rvm: jruby-head
21
+ - rvm: jruby-9.0.5.0
data/Changes.md ADDED
@@ -0,0 +1,11 @@
1
+ # Rspec Hanami Changes
2
+
3
+ HEAD
4
+ -----------
5
+
6
+ - Add request helpers (`get`, `post`, etc) [#5]
7
+ - Add new matcher `match_in_body` [#3]
8
+
9
+ 0.2.0
10
+ -----------
11
+
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in rspec-hanami.gemspec
4
4
  gemspec
5
+
6
+ gem 'coveralls', require: false
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # RSpec::Hanami
2
- **rspec-rails** is a testing framework for [hanami](http://hanamirb.org)
2
+
3
+ [![Build Status](https://travis-ci.org/davydovanton/rspec-hanami.svg?branch=master)](https://travis-ci.org/davydovanton/rspec-hanami) [![Coverage Status](https://coveralls.io/repos/github/davydovanton/rspec-hanami/badge.svg?branch=master)](https://coveralls.io/github/davydovanton/rspec-hanami?branch=master)
4
+
5
+ **rspec-hanami** is a testing framework for [hanami](http://hanamirb.org)
3
6
 
4
7
  ## Installation
5
8
  Add this line to your application's Gemfile:
@@ -18,7 +21,53 @@ Or install it yourself as:
18
21
 
19
22
  $ gem install rspec-hanami
20
23
 
24
+ After that require gem to `spec_helper.rb` and include matchers to rspec:
25
+
26
+ ```ruby
27
+ require 'rspec/hanami'
28
+
29
+ RSpec.configure do |config|
30
+ config.include RSpec::Hanami::Matchers
31
+
32
+ # ...
33
+ end
34
+ ```
35
+
36
+ ### Capybara
37
+ Check your `spec/features_helper.rb` and `spec/support/Capybara.rb` files. If you find something like this:
38
+
39
+ ```ruby
40
+ Capybara.app = Hanami::Container.new
41
+ # or
42
+ Capybara.app = Hanami::App.new
43
+ ```
44
+
45
+ Please change this line to:
46
+ ```ruby
47
+ Capybara.app = ::Hanami::Container.new
48
+ # or
49
+ Capybara.app = ::Hanami::App.new
50
+ ```
51
+
52
+ For more information see [this issue](https://github.com/davydovanton/rspec-hanami/issues/1)
53
+
21
54
  ## Supported matchers
55
+ ### Request helpers
56
+ You can use familiar request helpers like `#get`, `#post`, etc.
57
+ These methods make full hanami app request and return env (array with 3 elements).
58
+
59
+ For using these helpers include `RSpec::Hanami::RequestHelpers` to your `spec_helper.rb` file:
60
+
61
+ ```ruby
62
+ config.include RSpec::Hanami::RequestHelpers
63
+ ```
64
+
65
+ After that you can call any method:
66
+ ```ruby
67
+ it { expect(get('/')).to be_success }
68
+ it { expect(post('/tasks')).to redirect_to('/tasks') }
69
+ ```
70
+
22
71
  ### Controller Specs
23
72
  #### `have_http_status`
24
73
  Passes if `response` has a matching HTTP status code.
@@ -56,9 +105,18 @@ response = action.call(params)
56
105
  expect(response).to redirect_to('site.com')
57
106
  ```
58
107
 
108
+ #### `match_in_body`
109
+ Passes if `body` matches with argument
110
+
111
+ ``` ruby
112
+ response = action.call(params)
113
+ expect(response).to match_in_body('Tittle')
114
+ expect(response).to match_in_body(/Tittle\s\d+/)
115
+ ```
116
+
59
117
  ### Views Specs
60
118
  #### `have_action`
61
- Passes if form object has a action
119
+ Passes if form object has an action
62
120
 
63
121
  ``` ruby
64
122
  expect(view.form).to have_action('/users')
data/Rakefile CHANGED
@@ -7,4 +7,8 @@ Rake::TestTask.new(:test) do |t|
7
7
  t.test_files = FileList['test/**/*_test.rb']
8
8
  end
9
9
 
10
- task :default => :spec
10
+ task default: :spec
11
+ desc 'run Rspec specs'
12
+ task :spec do
13
+ sh 'rspec spec'
14
+ end
data/lib/rspec/hanami.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'rspec/hanami/version'
2
+ require 'rspec/hanami/request_helpers'
2
3
 
3
4
  module RSpec
4
5
  module Hanami
@@ -3,6 +3,7 @@ require 'rspec/expectations'
3
3
  require 'rspec/hanami/form_parser'
4
4
  require 'rspec/hanami/match_status'
5
5
  require 'rspec/hanami/matchers/have_http_status'
6
+ require 'rspec/hanami/matchers/match_in_body'
6
7
  require 'rspec/hanami/matchers/be_status'
7
8
  require 'rspec/hanami/matchers/form_matchers'
8
9
  require 'rspec/hanami/matchers/redirect_to'
@@ -59,7 +59,7 @@ module RSpec
59
59
  description { "have field with params" }
60
60
  match do |form|
61
61
  @form = form
62
- @params = ::Hanami::Utils::Hash.new(@params).symbolize!
62
+ @params = ::Hanami::Utils::Hash.new(params).symbolize!
63
63
  @form_data = RSpec::Hanami::FormParser.new.call(form.to_s)
64
64
 
65
65
  form_data.any? do |input|
@@ -0,0 +1,28 @@
1
+ module RSpec
2
+ module Hanami
3
+ module Matchers
4
+ extend ::RSpec::Matchers::DSL
5
+
6
+ # @api public
7
+ # Passes if `response` has a not 4xx and 5xx error code.
8
+ #
9
+ # @example Accepts numeric and symbol statuses
10
+ # response = action.call(params)
11
+ # expect(response).to be_success
12
+ #
13
+ matcher :match_in_body do |regexp|
14
+ attr_reader :actual, :object
15
+
16
+ description { "match #{regexp} in body" }
17
+ match do |object|
18
+ @object = object
19
+ @actual = object.last.first
20
+ !!actual.match(Regexp.new(regexp))
21
+ end
22
+
23
+ failure_message { |actual| "expect #{object} to have text #{regexp} in body" }
24
+ diffable
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,74 @@
1
+ module RSpec
2
+ module Hanami
3
+ module RequestHelpers
4
+ class Request
5
+ def initialize(method, path, options)
6
+ @path, @query_string = path.split('?', 2)
7
+ @method = method
8
+ @params = options[:params]
9
+ @headers = options[:headers] || {}
10
+ end
11
+
12
+ def env
13
+ default_env.tap do |env|
14
+ env['PATH_INFO'] = @path,
15
+ env['REQUEST_METHOD'] = @method,
16
+ env['QUERY_STRING'] = "?#{@query_string}"
17
+ env['rack.input'] = StringIO.new(@params.to_json) if @params
18
+
19
+ @headers.each do |key, value|
20
+ rack_name = key.upcase.tr('-', '_')
21
+ env["HTTP_#{rack_name}"] = value
22
+ end
23
+ end
24
+ end
25
+
26
+ def default_env
27
+ {
28
+ 'SCRIPT_NAME' => '',
29
+ 'SERVER_NAME' => 'localhost',
30
+ 'SERVER_PORT' => '800613',
31
+ 'rack.version' => [1, 3],
32
+ 'rack.url_scheme' => 'http',
33
+ 'rack.input' => StringIO.new,
34
+ 'rack.errors' => StringIO.new,
35
+ 'rack.multithread' => false,
36
+ 'rack.multiprocess' => false,
37
+ 'rack.run_once' => false,
38
+ 'rack.hijack?' => false
39
+ }
40
+ end
41
+ end
42
+
43
+ def self.included(klass)
44
+ klass.class_eval do
45
+ attr_reader :response
46
+ end
47
+ end
48
+
49
+ def request(request)
50
+ @response = ::Hanami.app.call(request.env)
51
+ end
52
+
53
+ def get(path, options = {})
54
+ request(Request.new('GET', path, options))
55
+ end
56
+
57
+ def post(path, options = {})
58
+ request(Request.new('POST', path, options))
59
+ end
60
+
61
+ def patch(path, options = {})
62
+ request(Request.new('PATCH', path, options))
63
+ end
64
+
65
+ def put(path, options = {})
66
+ request(Request.new('PUT', path, options))
67
+ end
68
+
69
+ def delete(path, options = {})
70
+ request(Request.new('DELETE', path, options))
71
+ end
72
+ end
73
+ end
74
+ end
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module Hanami
3
- VERSION = "0.2.0"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-hanami
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Davydov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-05-26 00:00:00.000000000 Z
11
+ date: 2018-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -90,6 +90,7 @@ files:
90
90
  - ".gitignore"
91
91
  - ".travis.yml"
92
92
  - CODE_OF_CONDUCT.md
93
+ - Changes.md
93
94
  - Gemfile
94
95
  - LICENSE.txt
95
96
  - README.md
@@ -101,7 +102,9 @@ files:
101
102
  - lib/rspec/hanami/matchers/be_status.rb
102
103
  - lib/rspec/hanami/matchers/form_matchers.rb
103
104
  - lib/rspec/hanami/matchers/have_http_status.rb
105
+ - lib/rspec/hanami/matchers/match_in_body.rb
104
106
  - lib/rspec/hanami/matchers/redirect_to.rb
107
+ - lib/rspec/hanami/request_helpers.rb
105
108
  - lib/rspec/hanami/version.rb
106
109
  - rspec-hanami.gemspec
107
110
  homepage: https://github.com/davydovanton/rspec-hanami
@@ -124,9 +127,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
127
  version: '0'
125
128
  requirements: []
126
129
  rubyforge_project:
127
- rubygems_version: 2.5.1
130
+ rubygems_version: 2.7.3
128
131
  signing_key:
129
132
  specification_version: 4
130
133
  summary: RSpec Matchers for Hanami
131
134
  test_files: []
132
- has_rdoc: