rspec-xunit 0.3.0 → 0.4.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
2
  SHA256:
3
- metadata.gz: 19215c9547e287899a24854728c7dbe40ddf27012b340698c2aad20b2a7b94b3
4
- data.tar.gz: e75a2c1d539bff30397b9658a371fe6136945f112ffeb65ea03a29ca9053717c
3
+ metadata.gz: d48b5d54ba47473aa22ac7ec656b7b3f772b6cbeb64d1bd4fc2f6717d0cf0775
4
+ data.tar.gz: 8cd92f78030c96d6d2c73b2fb0dc6853ec1a2b399af134160263a9fcc0ba56be
5
5
  SHA512:
6
- metadata.gz: 7e986afb74f97d4d1cba41a66f38f64a728aaf0fcee2db976e04bae669864d715ba786205dade7d284a36004a63abd85a89e236fdfaf78e73c3297f70ecb837b
7
- data.tar.gz: 05a1c176b31bc673aa72ed5b56f398b0857ae8ff02a7c4d27270a547466230c4002a3247d4e9388ff64b04b76e4caf2349f74ba31782236e2f476f09ffe9623c
6
+ metadata.gz: cbb7e89e1e735e8d593edf2c01b4b406a8af76ea2e59c81e4943e9ca72567460d431a61181c4826039dcf6fe7bfd7b0511f235c5b3e40a83b18f9022ab2c9e73
7
+ data.tar.gz: 70df062dddc7f78a23f67b7bb15429aa75459c65abeb4920f76048987662bf554790bc468f1974eca43f5081474527435f0774463a7e3c5f41aefa577cb45910
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ -Itest
2
+ --pattern='test/**/*_test.rb'
@@ -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, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ 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 gsamokovarov@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 [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in rspec-xunit.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Genadi Samokovarov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,178 @@
1
+ The RSpec you know and love with xUnit syntax.
2
+
3
+ ## BDD
4
+
5
+ ```ruby
6
+ require "rails_helper"
7
+
8
+ RSpec.describe Next::LoginForm do
9
+ it "validates a user can be found by email" do
10
+ login = Next::LoginForm.submit email: "oh@no.com", password: ":(",
11
+
12
+ expect(login).to be_invalid
13
+ expect(login.errors.details[:base]).to eq([error: :not_found])
14
+ end
15
+
16
+ it "validates a user can be authenticated" do
17
+ user = create :user
18
+
19
+ expect {
20
+ login = Next::LoginForm.submit email: user.email, password: user.password
21
+
22
+ expect(login).to be_valid
23
+ }.to change { Session.count }.by(1)
24
+ end
25
+ end
26
+ ```
27
+
28
+ 🤢
29
+
30
+ ## xUnit
31
+
32
+ ```ruby
33
+ require "test_helper"
34
+
35
+ RSpec.case Next::LoginForm do
36
+ test "user cannot be found" do
37
+ login = Next::LoginForm.submit email: "oh@no.com", password: ":("
38
+
39
+ assert_invalid? login
40
+ assert_eq login.errors.details[:base], [error: :not_found]
41
+ end
42
+
43
+ test "user authentication" do
44
+ user = create :user
45
+
46
+ assert_change Session, :count do
47
+ login = Next::LoginForm.submit email: user.email, password: user.password
48
+
49
+ assert_valid? login
50
+ end
51
+ end
52
+ end
53
+ ```
54
+
55
+ 🥳
56
+
57
+ ## Installation
58
+
59
+ Add `rspec-xunit` to both the `:development` and `:test` groups of your `Gemfile`:
60
+
61
+ ```ruby
62
+ group :development, :test do
63
+ gem 'rspec-xunit'
64
+ end
65
+ ```
66
+
67
+ If you want your tests in the `test` directory (as you should, my friend) put
68
+ this in your `.rspec` file:
69
+
70
+ ```
71
+ -Itest
72
+ --pattern='test/**/*_test.rb'
73
+ ```
74
+
75
+ ## Syntax
76
+
77
+ The syntax offered by `rspec-xunit` should be familiar to xUnit testing
78
+ framework users like `minitest`.
79
+
80
+ You start a test case by `RSpec.case`. This is a simple alias of
81
+ `Rspec.describe`. You define individual tests (what you call examples in your
82
+ past life) with the `test` macro. It is an alias of `it` and it supports all
83
+ it's goodies, like skipping a test with `xtest`.
84
+
85
+ This leaves us to at the most important change in `rspec-xunit`... You no
86
+ longer write **expectations** but **assertions**!
87
+
88
+ ### Assertions
89
+
90
+ Let's take a look at single RSpec BDD example:
91
+
92
+ ```ruby
93
+ it "validates a user can be found by email" do
94
+ login = Next::LoginForm.submit email: "oh@no.com", password: ":(",
95
+
96
+ expect(login).to be_invalid
97
+ expect(login.errors.details[:base]).to eq([error: :not_found])
98
+ end
99
+ ```
100
+
101
+ The line `expect(login).to be_invalid` as an **expectation**. The `be_invalid`
102
+ part of it is a **matcher**. For every RSpec matcher, we have a corresponding
103
+ **assertion**. This is how we can rewrite the example above as a test:
104
+
105
+ ```ruby
106
+ test "user cannot be found" do
107
+ login = Next::LoginForm.submit email: "oh@no.com", password: ":("
108
+
109
+ assert_invalid? login
110
+ assert_eq login.errors.details[:base], [error: :not_found]
111
+ end
112
+ ```
113
+
114
+ The assertions provided by `rspec-xunit` follow the pattern `assert_:matcher`,
115
+ where `:matcher` is a name of standard RSpec matcher. This way, every matcher
116
+ you expect from RSpec is already available in `rspec-xunit`. 🎉
117
+
118
+ We even support block matchers like:
119
+
120
+ ```ruby
121
+ test "missing required fields" do
122
+ assert_raise_error ActiveModel::ValidationError do
123
+ Next::LoginForm.submit!
124
+ end
125
+ end
126
+ ```
127
+
128
+ The test above is equivalent to the example below:
129
+
130
+ ```ruby
131
+ it "requires email and password present" do
132
+ expect {
133
+ Next::LoginForm.submit!
134
+ }.to raise_error(ActiveModel::ValidationError)
135
+ end
136
+ ```
137
+
138
+ We have the aliases of `assert_raise` and `assert_raises` to
139
+ `assert_raise_error` for that extra bittersweet xUnit feel. 🤤
140
+
141
+ Some block-level assertions, though are hard to convert. Take this example,
142
+ for example 😉:
143
+
144
+ ```ruby
145
+ it "validates a user can be authenticated" do
146
+ user = create :user
147
+
148
+ expect {
149
+ login = Next::LoginForm.submit email: user.email, password: user.password
150
+
151
+ expect(login).to be_valid
152
+ }.to change { Session.count }.by(1)
153
+ end
154
+ ```
155
+
156
+ We cannot translate `change { Session.count }.by(1)` to a nice assertion. This
157
+ is where the `assert` fall-back comes in:
158
+
159
+ ```ruby
160
+ test "user authentication" do
161
+ user = create :user
162
+
163
+ assert {
164
+ assert_valid? login
165
+ }.to change { Session.count }.by(1)
166
+ end
167
+ ```
168
+
169
+ This looks suspiciously like `expect` because it is its alias! 🙄 Sometimes
170
+ you just gotta `expect`, I mean `assert`, you know!
171
+
172
+ Have you noticed the `assert_valid? login` line? We call it an assertion
173
+ predicate! Every assertion ending in a question-mark invokes that predicate
174
+ method on the asserted object.
175
+
176
+ ```ruby
177
+ assert_empty? object_responding_to_empty_question_mark
178
+ ```
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rspec/xunit"
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/setup ADDED
@@ -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
@@ -0,0 +1,125 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSpec
4
+ module XUnit
5
+ # Assertions contains the XUnit friendly assertions to be used in RSpec
6
+ # examples.
7
+ module Assertions
8
+ class << self
9
+ # Assertion match converts RSpec matchers into an XUnit friendly
10
+ # assertions.
11
+ #
12
+ # For example: `assertion_match :eq` will create an `assert_eq` method
13
+ # behaving in the same way as:
14
+ #
15
+ # `expect(action).to eq(expected)`
16
+ def assertion_match(matcher, suffix = guess_assertion_suffix(matcher))
17
+ define_method "assert_#{suffix}" do |value, *args, &block|
18
+ begin
19
+ expect(value).to send(matcher, *args, &block)
20
+ rescue Expectations::ExpectationNotMetError => e
21
+ raise e, e.message, adjust_for_better_failure_message(e.backtrace), cause: nil
22
+ end
23
+ end
24
+ end
25
+
26
+ # Assertion match block converts RSpec block matchers into XUnit
27
+ # friendly assertions.
28
+ #
29
+ # For example: `assertion_match_block :raises, :raise_error` will
30
+ # create an `assert_raises` method behaving in the same way as:
31
+ #
32
+ # `expect { bloc }.to raise_error`
33
+ def assertion_match_block(matcher, suffix = guess_assertion_suffix(matcher))
34
+ define_method "assert_#{suffix}" do |*args, &block|
35
+ begin
36
+ expect(&block).to send(matcher, *args)
37
+ rescue Expectations::ExpectationNotMetError => e
38
+ raise e, e.message, adjust_for_better_failure_message(e.backtrace), cause: nil
39
+ end
40
+ end
41
+ end
42
+
43
+ private
44
+
45
+ MATCHER_CRUFT_REGEX = /((?:be_)|(?:have_))(.*)/.freeze
46
+
47
+ def guess_assertion_suffix(matcher_name)
48
+ MATCHER_CRUFT_REGEX.match(matcher_name) do |match|
49
+ match[2]
50
+ end || matcher_name
51
+ end
52
+ end
53
+
54
+ assertion_match :be_truthy
55
+ assertion_match :be_falsy
56
+ assertion_match :be_nil
57
+ assertion_match :be
58
+ assertion_match :be_a
59
+ assertion_match :be_a, :is_a
60
+ assertion_match :be_kind_of
61
+ assertion_match :be_instance_of
62
+ assertion_match :be_between
63
+ assertion_match :be_within
64
+ assertion_match :contain_exactly
65
+ assertion_match :cover
66
+ assertion_match :end_with
67
+ assertion_match :eq
68
+ assertion_match :equal
69
+ assertion_match :eql
70
+ assertion_match :exist
71
+ assertion_match :have_attributes
72
+ assertion_match :include
73
+ assertion_match :all
74
+ assertion_match :match
75
+ assertion_match :match_array
76
+ assertion_match :respond_to
77
+ assertion_match :satisfy
78
+ assertion_match :start_with
79
+ assertion_match :throw_symbol
80
+ assertion_match :throw_symbol, :throw
81
+ assertion_match :yield_control
82
+ assertion_match :yield_with_no_args
83
+ assertion_match :yield_successive_args
84
+
85
+ assertion_match_block :change
86
+ assertion_match_block :raise_error
87
+ assertion_match_block :raise_error, :raise
88
+ assertion_match_block :raise_error, :raises
89
+ assertion_match_block :output
90
+
91
+ # Assert is an alias to `expect`. Use it when all else fails or doesn't
92
+ # feel right. The `change` assertion with a block is a good example:
93
+ #
94
+ # `assert { block }.to change { value }`
95
+ def assert(value = Expectations::ExpectationTarget::UndefinedValue, &block)
96
+ Expectations::ExpectationTarget.for(value, block)
97
+ end
98
+
99
+ private
100
+
101
+ ASSERTION_PREDICATE_REGEX = /^assert_(.*)\?$/.freeze
102
+
103
+ def method_missing(method, *args, &block)
104
+ ASSERTION_PREDICATE_REGEX.match(method.to_s) do |match|
105
+ value = args.shift
106
+ matcher = "be_#{match[1]}"
107
+
108
+ expect(value).to Matchers::BuiltIn::BePredicate.new(matcher, *args, &block)
109
+ end || super
110
+ end
111
+
112
+ def respond_to_missing?(method, *)
113
+ method =~ ASSERTION_PREDICATE_REGEX || super
114
+ end
115
+
116
+ # TODO(genadi): Figure out where exactly the code shown in the failure
117
+ # message is extracted.
118
+ def adjust_for_better_failure_message(backtrace)
119
+ backtrace.drop_while { |trace| !trace.include?(__FILE__) }[1..-1]
120
+ end
121
+ end
122
+ end
123
+ end
124
+
125
+ RSpec::Matchers.include RSpec::XUnit::Assertions
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec::Core::ExampleGroup.define_example_group_method :case
4
+ RSpec::Core::ExampleGroup.define_example_group_method :fcase, focus: true
5
+ RSpec::Core::ExampleGroup.define_example_group_method :xcase, skip: 'Temporarily skipped with xcase'
6
+
7
+ RSpec::Core::ExampleGroup.define_example_method :test
8
+ RSpec::Core::ExampleGroup.define_example_method :ftest, focus: true
9
+ RSpec::Core::ExampleGroup.define_example_method :xtest, skip: 'Temporarily skipped with xtest'
10
+
11
+ RSpec::Core::Hooks.module_eval do
12
+ alias_method :setup, :before
13
+ alias_method :teardown, :after
14
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSpec
4
+ module XUnit
5
+ VERSION = '0.4.0'
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rspec/core'
4
+ require 'rspec/expectations'
5
+ require 'rspec/xunit/assertions'
6
+ require 'rspec/xunit/syntax'
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rspec/xunit'
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'rspec/xunit/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'rspec-xunit'
9
+ spec.version = RSpec::XUnit::VERSION
10
+ spec.authors = ['Genadi Samokovarov']
11
+ spec.email = ['gsamokovarov@gmail.com']
12
+ spec.summary = 'XUnit syntax for RSpec'
13
+ spec.description = 'XUnit syntax for RSpec'
14
+ spec.homepage = 'https://github.com/gsamokovarov/rspec-xunit'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
18
+ `git ls-files -z`.split("\x0").reject { |f| 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_dependency 'rspec-core', '>= 3.0'
25
+ spec.add_dependency 'rspec-expectations', '>= 3.0'
26
+
27
+ spec.add_development_dependency 'bundler', '~> 2.0'
28
+ spec.add_development_dependency 'rake', '~> 10.0'
29
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-xunit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genadi Samokovarov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-08-09 00:00:00.000000000 Z
11
+ date: 2019-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec-core
@@ -72,7 +72,22 @@ email:
72
72
  executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
- files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - CODE_OF_CONDUCT.md
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - lib/rspec-xunit.rb
86
+ - lib/rspec/xunit.rb
87
+ - lib/rspec/xunit/assertions.rb
88
+ - lib/rspec/xunit/syntax.rb
89
+ - lib/rspec/xunit/version.rb
90
+ - rspec-xunit.gemspec
76
91
  homepage: https://github.com/gsamokovarov/rspec-xunit
77
92
  licenses:
78
93
  - MIT