rspec-text-order 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 83b00f5f6bd71890577e57fb73a24fd370ef83d7
4
+ data.tar.gz: 02fd2ebbf433361c9f923b1e85264d548e0b96f5
5
+ SHA512:
6
+ metadata.gz: 448ff56c529624fab8bc9f6989159e7b882442016bb13f19237004967e9210c9633f24b82826c8c250ebf980993880df4abb314d82307c673b044d9852a47062
7
+ data.tar.gz: d882087ec8beb39a343f65a0a11dcfc9365eb7f750247381d883f759008a20d29f1eefdcc46dcf20b01649de422296685835e7a8d1e32ec49de7641cc437f1f6
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.ruby-version
3
+ /.yardoc
4
+ /*.gem
5
+ /Gemfile.lock
6
+ /_yardoc/
7
+ /coverage/
8
+ /doc/
9
+ /pkg/
10
+ /spec/reports/
11
+ /tmp/
12
+
13
+ # rspec failure tracking
14
+ .rspec_status
15
+ /spec/examples.txt
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --require spec_helper
2
+ --color
@@ -0,0 +1,7 @@
1
+ sudo: false
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.4.1
6
+ notifications:
7
+ email: false
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) { |repo| "https://github.com/#{repo}" }
4
+
5
+ gemspec
@@ -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,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rspec-text-order"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ #
4
+ # This file was generated by Bundler.
5
+ #
6
+ # The application 'rake' is installed as part of a gem, and
7
+ # this file is here to facilitate running it.
8
+ #
9
+
10
+ require "pathname"
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
12
+ Pathname.new(__FILE__).realpath)
13
+
14
+ require "rubygems"
15
+ require "bundler/setup"
16
+
17
+ load Gem.bin_path("rake", "rake")
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ #
4
+ # This file was generated by Bundler.
5
+ #
6
+ # The application 'rspec' is installed as part of a gem, and
7
+ # this file is here to facilitate running it.
8
+ #
9
+
10
+ require "pathname"
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
12
+ Pathname.new(__FILE__).realpath)
13
+
14
+ require "rubygems"
15
+ require "bundler/setup"
16
+
17
+ load Gem.bin_path("rspec-core", "rspec")
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
File without changes
@@ -0,0 +1,27 @@
1
+ require 'text_order/order'
2
+
3
+ module TextOrder
4
+ class After < Order
5
+ def matches?(actual)
6
+ super and is_after?(actual)
7
+ end
8
+
9
+ def failure_message
10
+ super or %{expected "#{expected}" to appear after "#{text}" in "#{actual}"}
11
+ end
12
+
13
+ def failure_message_when_negated
14
+ super or %{expected "#{expected}" not to appear after "#{text}" in "#{actual}"}
15
+ end
16
+
17
+ def before(text)
18
+ Before.new(self, text)
19
+ end
20
+
21
+ private
22
+
23
+ def is_after?(actual)
24
+ actual.index(expected) > actual.index(text)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ require 'text_order/order'
2
+
3
+ module TextOrder
4
+ class Before < Order
5
+ def matches?(actual)
6
+ super and is_before?(actual)
7
+ end
8
+
9
+ def failure_message
10
+ super or %{expected "#{expected}" to appear before "#{text}" in "#{actual}"}
11
+ end
12
+
13
+ def failure_message_when_negated
14
+ super or %{expected "#{expected}" not to appear before "#{text}" in "#{actual}"}
15
+ end
16
+
17
+ def after(text)
18
+ After.new(self, text)
19
+ end
20
+
21
+ private
22
+
23
+ def is_before?(actual)
24
+ actual.index(expected) < actual.index(text)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,33 @@
1
+ require 'text_order/after'
2
+ require 'text_order/before'
3
+
4
+ module TextOrder
5
+ class Matcher
6
+ attr_reader :actual, :expected
7
+
8
+ def initialize(expected)
9
+ @expected = expected
10
+ end
11
+
12
+ def matches?(actual)
13
+ @actual = actual
14
+ actual.include?(expected)
15
+ end
16
+
17
+ def failure_message
18
+ %{expected "#{actual}" to include the text "#{expected}"}
19
+ end
20
+
21
+ def failure_message_when_negated
22
+ %{expected "#{actual}" not to include the text "#{expected}"}
23
+ end
24
+
25
+ def after(text)
26
+ After.new(self, text)
27
+ end
28
+
29
+ def before(text)
30
+ Before.new(self, text)
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,35 @@
1
+ module TextOrder
2
+ class Order
3
+ attr_reader :matcher, :text
4
+
5
+ def initialize(matcher, text)
6
+ @matcher = matcher
7
+ @text = text
8
+ end
9
+
10
+ def actual
11
+ matcher.actual
12
+ end
13
+
14
+ def expected
15
+ matcher.expected
16
+ end
17
+
18
+ def matches?(actual)
19
+ @matched = matcher.matches?(actual)
20
+ end
21
+
22
+ def failure_message
23
+ matcher.failure_message unless matched?
24
+ end
25
+
26
+ def failure_message_when_negated
27
+ matcher.failure_message_when_negated unless matched?
28
+ end
29
+
30
+ private
31
+
32
+ attr_reader :matched
33
+ alias_method :matched?, :matched
34
+ end
35
+ end
@@ -0,0 +1,45 @@
1
+ require 'text_order/matcher'
2
+
3
+ module TextOrder
4
+ module RSpec
5
+ module Matchers
6
+ def include_text(expected)
7
+ Matcher.new(expected)
8
+ end
9
+ end
10
+ end
11
+ end
12
+
13
+ RSpec.configure do |config|
14
+ config.include TextOrder::RSpec::Matchers
15
+ end
16
+
17
+ RSpec::Matchers.define :appear_after do |expected|
18
+ match do |actual|
19
+ @matcher = TextOrder::Matcher.new(actual).after(expected)
20
+ @matcher.matches?(page.text)
21
+ end
22
+
23
+ failure_message do
24
+ @matcher.failure_message
25
+ end
26
+
27
+ failure_message_when_negated do
28
+ @matcher.failure_message_when_negated
29
+ end
30
+ end
31
+
32
+ RSpec::Matchers.define :appear_before do |expected|
33
+ match do |actual|
34
+ @matcher = TextOrder::Matcher.new(actual).before(expected)
35
+ @matcher.matches?(page.text)
36
+ end
37
+
38
+ failure_message do
39
+ @matcher.failure_message
40
+ end
41
+
42
+ failure_message_when_negated do
43
+ @matcher.failure_message_when_negated
44
+ end
45
+ end
@@ -0,0 +1,3 @@
1
+ module TextOrder
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "text_order/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'rspec-text-order'
8
+ spec.version = TextOrder::VERSION
9
+ spec.authors = ['Jay Hayes']
10
+ spec.email = ['ur@iamvery.com']
11
+
12
+ spec.summary = %q{An RSpec matcher that tests the text order on the page.}
13
+ spec.description = %q{An RSpec matcher that tests the text order on the page.}
14
+ spec.homepage = 'https://github.com/iamvery/rspec-text-order'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = 'exe'
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.15'
25
+ spec.add_development_dependency 'capybara', '~> 2.15'
26
+ spec.add_development_dependency 'rake', '~> 10.0'
27
+ spec.add_development_dependency 'rspec', '~> 3.0'
28
+ spec.add_development_dependency 'pry'
29
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec-text-order
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jay Hayes
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-11-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: capybara
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.15'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.15'
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
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: An RSpec matcher that tests the text order on the page.
84
+ email:
85
+ - ur@iamvery.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - Rakefile
95
+ - bin/console
96
+ - bin/rake
97
+ - bin/rspec
98
+ - bin/setup
99
+ - lib/rspec-text-order.rb
100
+ - lib/text_order/after.rb
101
+ - lib/text_order/before.rb
102
+ - lib/text_order/matcher.rb
103
+ - lib/text_order/order.rb
104
+ - lib/text_order/rspec.rb
105
+ - lib/text_order/version.rb
106
+ - rspec-text-order.gemspec
107
+ homepage: https://github.com/iamvery/rspec-text-order
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.6.13
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: An RSpec matcher that tests the text order on the page.
131
+ test_files: []