with_clues 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.circleci/config.yml +35 -0
- data/.gitignore +9 -0
- data/.rspec +1 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/CONTRIBUTING.md +5 -0
- data/Gemfile +6 -0
- data/LICENSE.md +33 -0
- data/README.md +159 -0
- data/Rakefile +2 -0
- data/bin/ci +10 -0
- data/bin/console +14 -0
- data/bin/mk_gem +73 -0
- data/bin/rake +29 -0
- data/bin/rspec +29 -0
- data/bin/setup +6 -0
- data/lib/with_clues.rb +3 -0
- data/lib/with_clues/browser_logs.rb +29 -0
- data/lib/with_clues/html.rb +16 -0
- data/lib/with_clues/method.rb +40 -0
- data/lib/with_clues/notifier.rb +19 -0
- data/lib/with_clues/version.rb +3 -0
- data/with_clues.gemspec +31 -0
- metadata +124 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a9250314165c2529d8ac1a12ccc085a2abf2098f057b5778b1544c34dff21f9c
|
4
|
+
data.tar.gz: 9f737b4264d64955b17174ac44c9336d8dfa8fe79152b00cf96447b48ac15208
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9bf1631b167e606916d8d7e87bba3236bf829c0614c722b05fc5ac99c103cd96fb44f4c1e548bbcdbfcc71205e3661ba9d9d58f0a844cf7c004dc618174ab253
|
7
|
+
data.tar.gz: cdb5e7836e91a48764ad70afeeed9f1aeaf872b3cf748c4663431e522cfc7f4006a00045ab7a03b7fa905d9865f5442dba5621b0e47172fa3c18b4738d1022fe
|
@@ -0,0 +1,35 @@
|
|
1
|
+
version: 2.1
|
2
|
+
orbs:
|
3
|
+
# See https://circleci.com/developer/orbs/orb/circleci/ruby
|
4
|
+
ruby: circleci/ruby@1.1.2
|
5
|
+
jobs: # keyword
|
6
|
+
test: # my name for the job
|
7
|
+
parameters: # keyword
|
8
|
+
ruby-version: # my parameter name
|
9
|
+
type: string # type is a keyword
|
10
|
+
docker: # keyword
|
11
|
+
- image: cimg/base:stable
|
12
|
+
steps: # keyword
|
13
|
+
- checkout # magic name
|
14
|
+
- ruby/install: # ruby/ is from the orb name, install is a command in that orb
|
15
|
+
version: << parameters.ruby-version >> # magic nonsense for param subst
|
16
|
+
- run:
|
17
|
+
command: "bin/setup"
|
18
|
+
- run:
|
19
|
+
name: "Create the test results directory because you can't just store_test_results with a file and if you do you do not get any sort of error because wtf is with this platform?"
|
20
|
+
command: mkdir -p /tmp/test-results
|
21
|
+
- run:
|
22
|
+
command: bin/ci /tmp/test-results/rspec_results.xml
|
23
|
+
- store_test_results: # store_test_results is magic from circle
|
24
|
+
path: /tmp/test-results # path is a param to store_test_results and it must be a directory not a file
|
25
|
+
- store_artifacts: # store_artifacts is magic from circle
|
26
|
+
path: /tmp/test-results # path is the param to store_artifacts
|
27
|
+
workflows: # keyword
|
28
|
+
all-rubies: # my name for the workflow
|
29
|
+
jobs: # keyword
|
30
|
+
- test: # my name for the job
|
31
|
+
matrix: # keyword
|
32
|
+
parameters: # keyword
|
33
|
+
# All rubies being maintained per this page:
|
34
|
+
# https://www.ruby-lang.org/en/downloads/branches/
|
35
|
+
ruby-version: [ "2.5", "2.6", "2.7", "3.0" ]
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--require spec_helper
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, sex characteristics, gender identity and expression,
|
9
|
+
level of experience, education, socio-economic status, nationality, personal
|
10
|
+
appearance, race, religion, or sexual identity and orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at davetron5000 (at) gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
|
72
|
+
|
73
|
+
[homepage]: https://www.contributor-covenant.org
|
74
|
+
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,5 @@
|
|
1
|
+
# Contributing
|
2
|
+
|
3
|
+
* Code changes for style, cleanliness, eleganance, or other aesthetic stuff will not be accepted.
|
4
|
+
* All proposed changes must have a clear problem statement and be based on a real-world scenario. Imagined problems will not be solved.
|
5
|
+
* Tests are appreciated with all pull requests.
|
data/Gemfile
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
[with_clues] Copyright (2021) (David Copeland)(“Licensor”)
|
2
|
+
|
3
|
+
Hippocratic License Version Number: 2.1.
|
4
|
+
|
5
|
+
Purpose. The purpose of this License is for the Licensor named above to permit the Licensee (as defined below) broad permission, if consistent with Human Rights Laws and Human Rights Principles (as each is defined below), to use and work with the Software (as defined below) within the full scope of Licensor’s copyright and patent rights, if any, in the Software, while ensuring attribution and protecting the Licensor from liability.
|
6
|
+
|
7
|
+
Permission and Conditions. The Licensor grants permission by this license (“License”), free of charge, to the extent of Licensor’s rights under applicable copyright and patent law, to any person or entity (the “Licensee”) obtaining a copy of this software and associated documentation files (the “Software”), to do everything with the Software that would otherwise infringe (i) the Licensor’s copyright in the Software or (ii) any patent claims to the Software that the Licensor can license or becomes able to license, subject to all of the following terms and conditions:
|
8
|
+
|
9
|
+
* Acceptance. This License is automatically offered to every person and entity subject to its terms and conditions. Licensee accepts this License and agrees to its terms and conditions by taking any action with the Software that, absent this License, would infringe any intellectual property right held by Licensor.
|
10
|
+
|
11
|
+
* Notice. Licensee must ensure that everyone who gets a copy of any part of this Software from Licensee, with or without changes, also receives the License and the above copyright notice (and if included by the Licensor, patent, trademark and attribution notice). Licensee must cause any modified versions of the Software to carry prominent notices stating that Licensee changed the Software. For clarity, although Licensee is free to create modifications of the Software and distribute only the modified portion created by Licensee with additional or different terms, the portion of the Software not modified must be distributed pursuant to this License. If anyone notifies Licensee in writing that Licensee has not complied with this Notice section, Licensee can keep this License by taking all practical steps to comply within 30 days after the notice. If Licensee does not do so, Licensee’s License (and all rights licensed hereunder) shall end immediately.
|
12
|
+
|
13
|
+
* Compliance with Human Rights Principles and Human Rights Laws.
|
14
|
+
|
15
|
+
1. Human Rights Principles.
|
16
|
+
|
17
|
+
(a) Licensee is advised to consult the articles of the United Nations Universal Declaration of Human Rights and the United Nations Global Compact that define recognized principles of international human rights (the “Human Rights Principles”). Licensee shall use the Software in a manner consistent with Human Rights Principles.
|
18
|
+
|
19
|
+
(b) Unless the Licensor and Licensee agree otherwise, any dispute, controversy, or claim arising out of or relating to (i) Section 1(a) regarding Human Rights Principles, including the breach of Section 1(a), termination of this License for breach of the Human Rights Principles, or invalidity of Section 1(a) or (ii) a determination of whether any Law is consistent or in conflict with Human Rights Principles pursuant to Section 2, below, shall be settled by arbitration in accordance with the Hague Rules on Business and Human Rights Arbitration (the “Rules”); provided, however, that Licensee may elect not to participate in such arbitration, in which event this License (and all rights licensed hereunder) shall end immediately. The number of arbitrators shall be one unless the Rules require otherwise.
|
20
|
+
|
21
|
+
Unless both the Licensor and Licensee agree to the contrary: (1) All documents and information concerning the arbitration shall be public and may be disclosed by any party; (2) The repository referred to under Article 43 of the Rules shall make available to the public in a timely manner all documents concerning the arbitration which are communicated to it, including all submissions of the parties, all evidence admitted into the record of the proceedings, all transcripts or other recordings of hearings and all orders, decisions and awards of the arbitral tribunal, subject only to the arbitral tribunal's powers to take such measures as may be necessary to safeguard the integrity of the arbitral process pursuant to Articles 18, 33, 41 and 42 of the Rules; and (3) Article 26(6) of the Rules shall not apply.
|
22
|
+
|
23
|
+
2. Human Rights Laws. The Software shall not be used by any person or entity for any systems, activities, or other uses that violate any Human Rights Laws. “Human Rights Laws” means any applicable laws, regulations, or rules (collectively, “Laws”) that protect human, civil, labor, privacy, political, environmental, security, economic, due process, or similar rights; provided, however, that such Laws are consistent and not in conflict with Human Rights Principles (a dispute over the consistency or a conflict between Laws and Human Rights Principles shall be determined by arbitration as stated above). Where the Human Rights Laws of more than one jurisdiction are applicable or in conflict with respect to the use of the Software, the Human Rights Laws that are most protective of the individuals or groups harmed shall apply.
|
24
|
+
|
25
|
+
3. Indemnity. Licensee shall hold harmless and indemnify Licensor (and any other contributor) against all losses, damages, liabilities, deficiencies, claims, actions, judgments, settlements, interest, awards, penalties, fines, costs, or expenses of whatever kind, including Licensor’s reasonable attorneys’ fees, arising out of or relating to Licensee’s use of the Software in violation of Human Rights Laws or Human Rights Principles.
|
26
|
+
|
27
|
+
* Failure to Comply. Any failure of Licensee to act according to the terms and conditions of this License is both a breach of the License and an infringement of the intellectual property rights of the Licensor (subject to exceptions under Laws, e.g., fair use). In the event of a breach or infringement, the terms and conditions of this License may be enforced by Licensor under the Laws of any jurisdiction to which Licensee is subject. Licensee also agrees that the Licensor may enforce the terms and conditions of this License against Licensee through specific performance (or similar remedy under Laws) to the extent permitted by Laws. For clarity, except in the event of a breach of this License, infringement, or as otherwise stated in this License, Licensor may not terminate this License with Licensee.
|
28
|
+
|
29
|
+
* Enforceability and Interpretation. If any term or provision of this License is determined to be invalid, illegal, or unenforceable by a court of competent jurisdiction, then such invalidity, illegality, or unenforceability shall not affect any other term or provision of this License or invalidate or render unenforceable such term or provision in any other jurisdiction; provided, however, subject to a court modification pursuant to the immediately following sentence, if any term or provision of this License pertaining to Human Rights Laws or Human Rights Principles is deemed invalid, illegal, or unenforceable against Licensee by a court of competent jurisdiction, all rights in the Software granted to Licensee shall be deemed null and void as between Licensor and Licensee. Upon a determination that any term or provision is invalid, illegal, or unenforceable, to the extent permitted by Laws, the court may modify this License to affect the original purpose that the Software be used in compliance with Human Rights Principles and Human Rights Laws as closely as possible. The language in this License shall be interpreted as to its fair meaning and not strictly for or against any party.
|
30
|
+
|
31
|
+
* Disclaimer. TO THE FULL EXTENT ALLOWED BY LAW, THIS SOFTWARE COMES “AS IS,” WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED, AND LICENSOR AND ANY OTHER CONTRIBUTOR SHALL NOT BE LIABLE TO ANYONE FOR ANY DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE OR THIS LICENSE, UNDER ANY KIND OF LEGAL CLAIM.
|
32
|
+
|
33
|
+
This Hippocratic License is an Ethical Source license (https://ethicalsource.dev) and is offered for use by licensors and licensees at their own risk, on an “AS IS” basis, and with no warranties express or implied, to the maximum extent permitted by Laws.
|
data/README.md
ADDED
@@ -0,0 +1,159 @@
|
|
1
|
+
# `with_clues` - temporarily provide more context when tests fail. Beats `puts`
|
2
|
+
|
3
|
+
Suppose you have this:
|
4
|
+
|
5
|
+
```ruby
|
6
|
+
expect(page).to have_content("My Awesome Site")
|
7
|
+
```
|
8
|
+
|
9
|
+
And Capybara says that that content is not there and that is all it says. You might slap in a `puts page.html` and try again.
|
10
|
+
Instead, what if you could not do that and do this?
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
with_clues do
|
14
|
+
expect(page).to have_content("My Awesome Site")
|
15
|
+
end
|
16
|
+
```
|
17
|
+
|
18
|
+
And *that* would print out your HTML? Or your JavaScript console? Or whatever else? Neat, right?
|
19
|
+
|
20
|
+
## Install
|
21
|
+
|
22
|
+
```
|
23
|
+
gem install with_clues
|
24
|
+
```
|
25
|
+
|
26
|
+
Or, in `Gemfile`:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
gem "with_clues"
|
30
|
+
```
|
31
|
+
|
32
|
+
For Rails, you might want to do this:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
gem "with_clues", group: :test
|
36
|
+
```
|
37
|
+
|
38
|
+
Then `bundle install`
|
39
|
+
|
40
|
+
## Setup
|
41
|
+
|
42
|
+
Best thing to do is mix into your base test class.
|
43
|
+
|
44
|
+
### For Minitest
|
45
|
+
|
46
|
+
If you are using Rails, probably something like this:
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
# test/test_helper.rb
|
50
|
+
require "with_clues"
|
51
|
+
|
52
|
+
class ActiveSupport::TestCase
|
53
|
+
include WithClues::Method
|
54
|
+
|
55
|
+
# ...
|
56
|
+
end
|
57
|
+
```
|
58
|
+
|
59
|
+
If you aren't using Rails, add the `require` and `include` wherever you configure your base test case (or just put it in each test individually).
|
60
|
+
|
61
|
+
### For RSpec
|
62
|
+
|
63
|
+
You'll want to put this in your `spec/spec_helper.rb` file:
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
require "with_clues"
|
67
|
+
RSpec.configure do |c|
|
68
|
+
c.include WithClues::Method
|
69
|
+
end
|
70
|
+
```
|
71
|
+
|
72
|
+
## Use
|
73
|
+
|
74
|
+
In general, you would not want to wrap all tests with `with_clues`. This is a diagnostic tool to allow you to get more
|
75
|
+
information on a test that is failing. As such, your workflow might be:
|
76
|
+
|
77
|
+
1. Notice a test failing that you cannot easily diagnose
|
78
|
+
1. Wrap the failing assertion in `with_clues`:
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
with_clues do
|
82
|
+
expect(page).to have_selector("div.foo.bar")
|
83
|
+
end
|
84
|
+
```
|
85
|
+
1. Run the test again, and see the additional info.
|
86
|
+
1. Once you've made the test pass, remove `with_clues`
|
87
|
+
|
88
|
+
## Included Clues
|
89
|
+
|
90
|
+
There are three clues included:
|
91
|
+
|
92
|
+
* Dumping HTML - when `page` exists, it will dump the contents of `page.html` when the test fails
|
93
|
+
* Dumping Browser logs - for a browser-based test, it will dump anything that was `console.log`'ed
|
94
|
+
* Arbitrary context you pass in, for example when testing an Active Record
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
person = Person.where(name: "Pat")
|
98
|
+
with_clues(person.inspect) do
|
99
|
+
expect(person.valid?).to eq(true)
|
100
|
+
end
|
101
|
+
```
|
102
|
+
|
103
|
+
If the test fails, `person.inspect` is included in the output
|
104
|
+
|
105
|
+
## Adding Your Own Clues
|
106
|
+
|
107
|
+
`with_clues` is intended as a diagnostic tool you can develop and enhance over time. As your team writes more code or develops
|
108
|
+
more conventions, you can develop diagnostics as well.
|
109
|
+
|
110
|
+
To add one, create a class that implements `dump(notifier, context:)`:
|
111
|
+
|
112
|
+
* `notifier` is a `WithClues::Notifier` that you should use to produce output:
|
113
|
+
* `notify` - output text, preceded with `[ with_clues ]` (this is so you can tell output from your code vs from `with_clues`)
|
114
|
+
* `blank_line` - a blank line (no prefix)
|
115
|
+
* `notify_raw` - output text without a prefix, useful for removing ambiguity about what is being output
|
116
|
+
* `context:` the context passed into `with_clues` (nil if it was omitted)
|
117
|
+
|
118
|
+
For example, suppose you want to output information about an Active Record like so:
|
119
|
+
|
120
|
+
```ruby
|
121
|
+
with_clues(person) do
|
122
|
+
# some test
|
123
|
+
end
|
124
|
+
```
|
125
|
+
|
126
|
+
If this test fails, you output the person's ID and any `errors`.
|
127
|
+
|
128
|
+
Create this class, e.g. in `spec/support/active_record_clues.rb`:
|
129
|
+
|
130
|
+
```ruby
|
131
|
+
class ActiveRecordClues
|
132
|
+
def dump(notifier, context:)
|
133
|
+
if context.kind_of?(ActiveRecord::Base)
|
134
|
+
notifier.notify "#{context.class}: id: #{context.id}"
|
135
|
+
notifier.notify "#{context.class}: errors: #{context.errors.inspect}"
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
```
|
140
|
+
|
141
|
+
To use it, call `WithClues::Method.use_custom_clue`, for example, in your `spec_helper.rb`:
|
142
|
+
|
143
|
+
```ruby
|
144
|
+
require "with_clues"
|
145
|
+
require_relative "support/active_record_clues"
|
146
|
+
|
147
|
+
RSpec.configure do |c|
|
148
|
+
c.include WithClues::Method
|
149
|
+
end
|
150
|
+
|
151
|
+
WithClues::Method.use_custom_clue ActiveRecordClues
|
152
|
+
```
|
153
|
+
|
154
|
+
You can use multiple clues by repeatedly calling `use_custom_clue`
|
155
|
+
|
156
|
+
## Developing
|
157
|
+
|
158
|
+
* Get set up with `bin/setup`
|
159
|
+
* Run tests with `bin/ci`
|
data/Rakefile
ADDED
data/bin/ci
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "with_clues"
|
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__)
|
data/bin/mk_gem
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "fileutils"
|
4
|
+
require "pathname"
|
5
|
+
|
6
|
+
include FileUtils
|
7
|
+
|
8
|
+
gem_name = ARGV[0]
|
9
|
+
|
10
|
+
if gem_name.nil?
|
11
|
+
puts "usage: #{$0} gem_name"
|
12
|
+
exit 1
|
13
|
+
end
|
14
|
+
|
15
|
+
root = Pathname(__FILE__).dirname / ".."
|
16
|
+
|
17
|
+
module_name = gem_name.split(/_/).map { |part|
|
18
|
+
part.capitalize
|
19
|
+
}.join
|
20
|
+
|
21
|
+
mkdir_p root / "lib"
|
22
|
+
|
23
|
+
File.open(root / "lib" / "#{gem_name}.rb", "w") do |file|
|
24
|
+
file.puts "module #{module_name}"
|
25
|
+
file.puts "end"
|
26
|
+
end
|
27
|
+
|
28
|
+
mkdir_p root / "lib" / gem_name
|
29
|
+
|
30
|
+
File.open(root / "lib" / gem_name / "version.rb", "w") do |file|
|
31
|
+
file.puts "module #{module_name}"
|
32
|
+
file.puts " VERSION=\"1.0.0\""
|
33
|
+
file.puts "end"
|
34
|
+
end
|
35
|
+
|
36
|
+
gemspec = File.read("rubygem.gemspec")
|
37
|
+
File.open(root / "#{gem_name}.gemspec","w") do |file|
|
38
|
+
file.puts "require_relative \"lib/#{gem_name}/version\""
|
39
|
+
file.puts
|
40
|
+
gemspec.split(/\n/).each do |line|
|
41
|
+
if line =~ /^\s*spec.name/
|
42
|
+
file.puts " spec.name = \"#{gem_name}\""
|
43
|
+
elsif line =~ /^\s*spec.version/
|
44
|
+
file.puts " spec.version = #{module_name}::VERSION"
|
45
|
+
elsif line.include?("«gem_name»")
|
46
|
+
file.puts line.gsub(/«gem_name»/,gem_name)
|
47
|
+
else
|
48
|
+
file.puts line
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
license = File.read(root / "LICENSE.md")
|
54
|
+
File.open(root / "LICENSE.md","w") do |file|
|
55
|
+
license.split(/\n/).each_with_index do |line,index|
|
56
|
+
if index == 0
|
57
|
+
file.puts "[#{gem_name}] Copyright (2021) (David Copeland)(“Licensor”)"
|
58
|
+
else
|
59
|
+
file.puts line
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
readme = File.read(root / "README.md")
|
65
|
+
File.open(root / "README.md","w") do |file|
|
66
|
+
license.split(/\n/).each_with_index do |line,index|
|
67
|
+
if index == 0
|
68
|
+
file.puts "# #{gem_name} - does a thing"
|
69
|
+
else
|
70
|
+
file.puts line
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/bin/rake
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'rake' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
require "pathname"
|
12
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
13
|
+
Pathname.new(__FILE__).realpath)
|
14
|
+
|
15
|
+
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
16
|
+
|
17
|
+
if File.file?(bundle_binstub)
|
18
|
+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
19
|
+
load(bundle_binstub)
|
20
|
+
else
|
21
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
22
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
require "rubygems"
|
27
|
+
require "bundler/setup"
|
28
|
+
|
29
|
+
load Gem.bin_path("rake", "rake")
|
data/bin/rspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'rspec' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
require "pathname"
|
12
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
13
|
+
Pathname.new(__FILE__).realpath)
|
14
|
+
|
15
|
+
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
16
|
+
|
17
|
+
if File.file?(bundle_binstub)
|
18
|
+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
19
|
+
load(bundle_binstub)
|
20
|
+
else
|
21
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
22
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
require "rubygems"
|
27
|
+
require "bundler/setup"
|
28
|
+
|
29
|
+
load Gem.bin_path("rspec-core", "rspec")
|
data/bin/setup
ADDED
data/lib/with_clues.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
module WithClues
|
2
|
+
class BrowserLogs
|
3
|
+
def dump(notifier, page:, context:)
|
4
|
+
if !page.respond_to?(:driver)
|
5
|
+
notifier.notify "Something may be wrong. page (#{page.class}) does not respond to #driver"
|
6
|
+
return
|
7
|
+
end
|
8
|
+
if page.driver.respond_to?(:browser)
|
9
|
+
if page.driver.browser.respond_to?(:manage)
|
10
|
+
if page.driver.browser.manage.respond_to?(:logs)
|
11
|
+
logs = page.driver.browser.manage.logs
|
12
|
+
browser_logs = logs.get(:browser)
|
13
|
+
notifier.notify "BROWSER LOGS {"
|
14
|
+
browser_logs.each do |log|
|
15
|
+
notifier.notify_raw log.message
|
16
|
+
end
|
17
|
+
notifier.notify "} END BROWSER LOGS"
|
18
|
+
else
|
19
|
+
notifier.notify "NO BROWSER LOGS: page.driver.browser.manage #{page.driver.browser.manage.class} does not respond to #logs"
|
20
|
+
end
|
21
|
+
else
|
22
|
+
notifier.notify "NO BROWSER LOGS: page.driver.browser #{page.driver.browser.class} does not respond to #manage"
|
23
|
+
end
|
24
|
+
else
|
25
|
+
notifier.notify "NO BROWSER LOGS: page.driver #{page.driver.class} does not respond to #browser"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module WithClues
|
2
|
+
class Html
|
3
|
+
def dump(notifier, page:, context:)
|
4
|
+
if !page.respond_to?(:html)
|
5
|
+
notifier.notify "Something may be wrong. page (#{page.class}) does not respond to #html"
|
6
|
+
return
|
7
|
+
end
|
8
|
+
notifier.blank_line
|
9
|
+
notifier.notify "HTML {"
|
10
|
+
notifier.blank_line
|
11
|
+
notifier.notify_raw page.html
|
12
|
+
notifier.blank_line
|
13
|
+
notifier.notify "} END HTML"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require_relative "html"
|
2
|
+
require_relative "browser_logs"
|
3
|
+
require_relative "notifier"
|
4
|
+
|
5
|
+
module WithClues
|
6
|
+
module Method
|
7
|
+
@@clue_classes = {
|
8
|
+
require_page: [
|
9
|
+
WithClues::BrowserLogs,
|
10
|
+
WithClues::Html,
|
11
|
+
],
|
12
|
+
custom: []
|
13
|
+
}
|
14
|
+
# Wrap any assertion with this method to get more
|
15
|
+
# useful context and diagnostics when a test is
|
16
|
+
# unexpectedly failing
|
17
|
+
def with_clues(context=nil, &block)
|
18
|
+
notifier = WithClues::Notifier.new($stdout)
|
19
|
+
block.()
|
20
|
+
notifier.notify "A passing test has been wrapped with `with_clues`. You should remove the call to `with_clues`"
|
21
|
+
rescue Exception => ex
|
22
|
+
notifier.notify context
|
23
|
+
@@clue_classes[:custom].each do |klass|
|
24
|
+
klass.new.dump(notifier, context: context)
|
25
|
+
end
|
26
|
+
if !defined?(page)
|
27
|
+
raise ex
|
28
|
+
end
|
29
|
+
notifier.notify "Test failed: #{ex.message}"
|
30
|
+
@@clue_classes[:require_page].each do |klass|
|
31
|
+
klass.new.dump(notifier, context: context, page: page)
|
32
|
+
end
|
33
|
+
raise ex
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.use_custom_clue(klass)
|
37
|
+
@@clue_classes[:custom] << klass
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module WithClues
|
2
|
+
class Notifier
|
3
|
+
def initialize(io)
|
4
|
+
@io = io
|
5
|
+
end
|
6
|
+
|
7
|
+
def blank_line
|
8
|
+
self.notify_raw("")
|
9
|
+
end
|
10
|
+
|
11
|
+
def notify(message)
|
12
|
+
@io.puts "[ with_clues ] #{message}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def notify_raw(message)
|
16
|
+
@io.puts message
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/with_clues.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require_relative "lib/with_clues/version"
|
2
|
+
|
3
|
+
#require_relative "lib/«gem»/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "with_clues"
|
7
|
+
spec.version = WithClues::VERSION
|
8
|
+
spec.authors = ["Dave Copeland"]
|
9
|
+
spec.email = ["davec@naildrivin5.com"]
|
10
|
+
spec.summary = %q{WTF does this do?}
|
11
|
+
spec.homepage = "https://sustainable-rails.com"
|
12
|
+
spec.license = "Hippocratic"
|
13
|
+
|
14
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
|
15
|
+
|
16
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
17
|
+
spec.metadata["source_code_uri"] = "https://github.com/sustainable-rails/with_clues"
|
18
|
+
spec.metadata["changelog_uri"] = "https://github.com/sustainable-rails/with_clues/releases"
|
19
|
+
|
20
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
21
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
|
+
end
|
23
|
+
spec.bindir = "exe"
|
24
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
|
+
spec.require_paths = ["lib"]
|
26
|
+
|
27
|
+
spec.add_development_dependency("rspec")
|
28
|
+
spec.add_development_dependency("minitest")
|
29
|
+
spec.add_development_dependency("capybara")
|
30
|
+
spec.add_development_dependency("rspec_junit_formatter")
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: with_clues
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dave Copeland
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-03-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: capybara
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec_junit_formatter
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- davec@naildrivin5.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".circleci/config.yml"
|
77
|
+
- ".gitignore"
|
78
|
+
- ".rspec"
|
79
|
+
- CODE_OF_CONDUCT.md
|
80
|
+
- CONTRIBUTING.md
|
81
|
+
- Gemfile
|
82
|
+
- LICENSE.md
|
83
|
+
- README.md
|
84
|
+
- Rakefile
|
85
|
+
- bin/ci
|
86
|
+
- bin/console
|
87
|
+
- bin/mk_gem
|
88
|
+
- bin/rake
|
89
|
+
- bin/rspec
|
90
|
+
- bin/setup
|
91
|
+
- lib/with_clues.rb
|
92
|
+
- lib/with_clues/browser_logs.rb
|
93
|
+
- lib/with_clues/html.rb
|
94
|
+
- lib/with_clues/method.rb
|
95
|
+
- lib/with_clues/notifier.rb
|
96
|
+
- lib/with_clues/version.rb
|
97
|
+
- with_clues.gemspec
|
98
|
+
homepage: https://sustainable-rails.com
|
99
|
+
licenses:
|
100
|
+
- Hippocratic
|
101
|
+
metadata:
|
102
|
+
homepage_uri: https://sustainable-rails.com
|
103
|
+
source_code_uri: https://github.com/sustainable-rails/with_clues
|
104
|
+
changelog_uri: https://github.com/sustainable-rails/with_clues/releases
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options: []
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: 2.5.0
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
requirements: []
|
120
|
+
rubygems_version: 3.1.2
|
121
|
+
signing_key:
|
122
|
+
specification_version: 4
|
123
|
+
summary: WTF does this do?
|
124
|
+
test_files: []
|