rspec-html 0.1.0 → 0.1.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7f8ba6978f02ad1d8763eb137332a30db8807af2f1f484b843cf65e41afffa5e
4
- data.tar.gz: 3619e2e57b5f05c45a7f2bc6612a8e8f1a7c6ce5b8628a3be2bee9d16a2e5835
3
+ metadata.gz: 8b6fbffdbd1506e148ae25b7900d508e3f50048cb3c2d27ed25ef2fd5a93d0ab
4
+ data.tar.gz: 8868853f56675ca2d4487b155a8da72c668ed6f80ebf61885f718a653d3b58a5
5
5
  SHA512:
6
- metadata.gz: df6d3216cf9bf3ea3d4db4149420aaaf9fc8ea7342bc03142b1e82cde2d71ec4f4a653b1dd94b2c3cfdeb88309b5416c5c575e5bed706d7d0b615407ff7da358
7
- data.tar.gz: 18c22ee25803f0fb6f01f772e44c55b7dc2a17f02911721ccd7f56304d5b2ad7ed611eab2c38030e6a40f4cf99954087b31db61ba24cd73e0035f878f6d7e7ba
6
+ metadata.gz: 63b9fa7b4043a45485bb6423c26ab1812e8ab56283285ad6f3e92402fe4f47c5a20e5f62b1102816f5a24a25c04965310464e69eacfc0619e7500cf716bde298
7
+ data.tar.gz: 1065cfee90afa2c3372c524abf7e6a7383c56f6e349d35f1f9bbe06b6e803665459c41f7360d9066baeccd5375d4a666cddd64f4921be85dd5b25faa668453dd
data/.gitignore CHANGED
@@ -12,3 +12,5 @@
12
12
 
13
13
  *.swp
14
14
  *.swo
15
+ .byebug_history
16
+ rspec-html-*.gem
@@ -2,17 +2,24 @@ PATH
2
2
  remote: .
3
3
  specs:
4
4
  rspec-html (0.1.0)
5
+ nokogiri (~> 1.10)
5
6
  rspec (~> 3.0)
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
9
10
  specs:
10
11
  ast (2.4.0)
12
+ betterp (0.1.3)
13
+ paint (~> 2.0)
14
+ byebug (11.0.1)
11
15
  concurrent-ruby (1.1.5)
12
16
  diff-lcs (1.3)
13
17
  i18n (1.7.0)
14
18
  concurrent-ruby (~> 1.0)
15
19
  jaro_winkler (1.5.4)
20
+ mini_portile2 (2.4.0)
21
+ nokogiri (1.10.5)
22
+ mini_portile2 (~> 2.4.0)
16
23
  paint (2.1.1)
17
24
  parallel (1.19.1)
18
25
  parser (2.6.5.0)
@@ -54,7 +61,10 @@ PLATFORMS
54
61
  ruby
55
62
 
56
63
  DEPENDENCIES
64
+ betterp (~> 0.1.3)
57
65
  bundler (~> 2.0)
66
+ byebug (~> 11.0)
67
+ i18n (~> 1.7)
58
68
  rake (~> 10.0)
59
69
  rspec-html!
60
70
  rspec-its (~> 1.3)
data/README.md CHANGED
@@ -1,17 +1,14 @@
1
- # Rspec::Html
1
+ # RSpec::HTML
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rspec/html`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ _RSpec::HTML_ provides a simple object interface to HTML responses from [_RSpec Rails_ request specs](https://relishapp.com/rspec/rspec-rails/docs/request-specs/request-spec).
6
4
 
7
5
  ## Installation
8
6
 
9
- Add this line to your application's Gemfile:
10
-
11
7
  ```ruby
12
- gem 'rspec-html'
8
+ gem 'rspec-html', '~> 0.1.1'
13
9
  ```
14
10
 
11
+ Bundle
15
12
  And then execute:
16
13
 
17
14
  $ bundle
@@ -22,18 +19,28 @@ Or install it yourself as:
22
19
 
23
20
  ## Usage
24
21
 
25
- TODO: Write usage instructions here
22
+ Require the gem in your `spec_helper.rb`:
26
23
 
27
- ## Development
24
+ ```
25
+ # spec/spec_helper.rb
26
+ require 'rspec/html'
27
+ ```
28
28
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
29
+ In request specs, access the HTML document through the provided object interface:
30
30
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
31
+ ```ruby
32
+ RSpec.describe 'something', type: :request do
33
+ it 'does something' do
34
+ get '/'
35
+ expect(document.body).to include 'something'
36
+ end
37
+ end
38
+ ```
32
39
 
33
40
  ## Contributing
34
41
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rspec-html.
42
+ Feel free to make a pull request.
36
43
 
37
44
  ## License
38
45
 
39
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
46
+ [MIT License](LICENSE)
@@ -1,10 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'rspec'
4
+ require 'rspec_html'
5
+
3
6
  require 'rspec/html/version'
4
7
 
5
- module Rspec
6
- module Html
7
- class Error < StandardError; end
8
- # Your code goes here...
8
+ module RSpec
9
+ # Module extension for RSpec::SharedContext
10
+ module HTML
11
+ def document
12
+ RSpecHTML::Document.new(response.body)
13
+ end
9
14
  end
10
15
  end
16
+
17
+ RSpec.configure do |config|
18
+ config.include RSpec::HTML
19
+ config.backtrace_exclusion_patterns << %r{/lib/rspec/html}
20
+ end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Rspec
4
- module Html
5
- VERSION = '0.1.0'
3
+ module RSpec
4
+ module HTML
5
+ VERSION = '0.1.1'
6
6
  end
7
7
  end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'nokogiri'
4
+ require 'pathname'
5
+
6
+ require 'rspec_html/nameable'
7
+ require 'rspec_html/searchable'
8
+ require 'rspec_html/body'
9
+ require 'rspec_html/document'
10
+ require 'rspec_html/head'
11
+ require 'rspec_html/title'
12
+
13
+ # Support module for rspec/html
14
+ module RSpecHTML
15
+ def self.root
16
+ Pathname.new(__dir__).parent
17
+ end
18
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSpecHTML
4
+ # HTML/BODY abstraction
5
+ class Body
6
+ include Searchable
7
+ include Nameable
8
+
9
+ def initialize(parsed_html)
10
+ @name = :body
11
+ @entity = parsed_html.css('body')
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSpecHTML
4
+ # HTML Document representation
5
+ class Document
6
+ def initialize(html)
7
+ @html = html
8
+ end
9
+
10
+ def body
11
+ Body.new(parsed_html)
12
+ end
13
+
14
+ def head
15
+ Head.new(parsed_html)
16
+ end
17
+
18
+ private
19
+
20
+ def parsed_html
21
+ @parsed_html ||= Nokogiri::HTML(@html)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSpecHTML
4
+ # HTML/BODY abstraction
5
+ class Head
6
+ include Nameable
7
+
8
+ def initialize(parsed_html)
9
+ @parsed_html = parsed_html
10
+ @entity = parsed_html.css('head')
11
+ @name = :head
12
+ end
13
+
14
+ def title
15
+ Title.new(@parsed_html)
16
+ end
17
+
18
+ def include?(val)
19
+ title.include?(val)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSpecHTML
4
+ # Mixin module providing methods allowing an entity to specify its name
5
+ module Nameable
6
+ attr_reader :name
7
+ end
8
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSpecHTML
4
+ # Mixin module providing methods for searching text content of HTML entities
5
+ module Searchable
6
+ def include?(val)
7
+ @entity.text.include?(val)
8
+ end
9
+
10
+ def to_s
11
+ @entity.text.strip
12
+ end
13
+
14
+ def inspect
15
+ %("#{self}")
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSpecHTML
4
+ # HTML/HEAD/TITLE abstraction
5
+ class Title
6
+ include Searchable
7
+ include Nameable
8
+
9
+ def initialize(parsed_html)
10
+ @name = :title
11
+ @entity = parsed_html.css('head title')
12
+ end
13
+ end
14
+ end
@@ -6,7 +6,7 @@ require 'rspec/html/version'
6
6
 
7
7
  Gem::Specification.new do |spec|
8
8
  spec.name = 'rspec-html'
9
- spec.version = Rspec::Html::VERSION
9
+ spec.version = RSpec::HTML::VERSION
10
10
  spec.authors = ['Bob Farrell']
11
11
  spec.email = ['git@bob.frl']
12
12
 
@@ -28,9 +28,13 @@ Gem::Specification.new do |spec|
28
28
  spec.executables = []
29
29
  spec.require_paths = ['lib']
30
30
 
31
+ spec.add_dependency 'nokogiri', '~> 1.10'
31
32
  spec.add_dependency 'rspec', '~> 3.0'
32
33
 
34
+ spec.add_development_dependency 'betterp', '~> 0.1.3'
33
35
  spec.add_development_dependency 'bundler', '~> 2.0'
36
+ spec.add_development_dependency 'byebug', '~> 11.0'
37
+ spec.add_development_dependency 'i18n', '~> 1.7'
34
38
  spec.add_development_dependency 'rake', '~> 10.0'
35
39
  spec.add_development_dependency 'rspec-its', '~> 1.3'
36
40
  spec.add_development_dependency 'rubocop', '~> 0.76.0'
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-html
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
  - Bob Farrell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-23 00:00:00.000000000 Z
11
+ date: 2019-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rspec
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -24,6 +38,20 @@ dependencies:
24
38
  - - "~>"
25
39
  - !ruby/object:Gem::Version
26
40
  version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: betterp
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.1.3
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.1.3
27
55
  - !ruby/object:Gem::Dependency
28
56
  name: bundler
29
57
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +66,34 @@ dependencies:
38
66
  - - "~>"
39
67
  - !ruby/object:Gem::Version
40
68
  version: '2.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '11.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '11.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: i18n
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.7'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.7'
41
97
  - !ruby/object:Gem::Dependency
42
98
  name: rake
43
99
  requirement: !ruby/object:Gem::Requirement
@@ -129,6 +185,13 @@ files:
129
185
  - bin/setup
130
186
  - lib/rspec/html.rb
131
187
  - lib/rspec/html/version.rb
188
+ - lib/rspec_html.rb
189
+ - lib/rspec_html/body.rb
190
+ - lib/rspec_html/document.rb
191
+ - lib/rspec_html/head.rb
192
+ - lib/rspec_html/nameable.rb
193
+ - lib/rspec_html/searchable.rb
194
+ - lib/rspec_html/title.rb
132
195
  - rspec-html.gemspec
133
196
  homepage: https://github.com/bobf/rspec-html
134
197
  licenses: