rspec-xunit 0.4.0 → 0.5.0
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 +4 -4
- data/Gemfile +2 -0
- data/README.md +8 -3
- data/lib/rspec/xunit/assertions.rb +71 -53
- data/lib/rspec/xunit/version.rb +1 -1
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 713f3c53c0bd3aad430437522e74b80d908906ab961722eb20d9a69b22172dde
         | 
| 4 | 
            +
              data.tar.gz: 04d407dfa15abe6a3916a9352d456a0b6397beebadfb6add22246889cca546ba
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: e34fc54d2bc49c960802fbb767c53a3d30d4021f0fc02d9992d20b8c93eeca98a69f769f7361097f88919b132672cfea0284a24d7663bbc62fc475ca2dc2e353
         | 
| 7 | 
            +
              data.tar.gz: 8e8e894a5ecefd0d7aba030909924a578c61ea707466354961bcce8c8b091a9c2ba0f5422362b3fc7b6cfff9d2ce4e8b4ea9bf0464b94eb58172851454030b27
         | 
    
        data/Gemfile
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | @@ -138,7 +138,7 @@ end | |
| 138 138 | 
             
            We have the aliases of `assert_raise` and `assert_raises` to
         | 
| 139 139 | 
             
            `assert_raise_error` for that extra bittersweet xUnit feel. 🤤
         | 
| 140 140 |  | 
| 141 | 
            -
            Some block-level assertions | 
| 141 | 
            +
            Some block-level assertions are hard to convert. Take this example,
         | 
| 142 142 | 
             
            for example 😉:
         | 
| 143 143 |  | 
| 144 144 | 
             
            ```ruby
         | 
| @@ -154,13 +154,13 @@ end | |
| 154 154 | 
             
            ```
         | 
| 155 155 |  | 
| 156 156 | 
             
            We cannot translate `change { Session.count }.by(1)` to a nice assertion. This
         | 
| 157 | 
            -
            is where the `assert | 
| 157 | 
            +
            is where the `assert!` fall-back comes in:
         | 
| 158 158 |  | 
| 159 159 | 
             
            ```ruby
         | 
| 160 160 | 
             
            test "user authentication" do
         | 
| 161 161 | 
             
              user = create :user
         | 
| 162 162 |  | 
| 163 | 
            -
              assert {
         | 
| 163 | 
            +
              assert! {
         | 
| 164 164 | 
             
                assert_valid? login
         | 
| 165 165 | 
             
              }.to change { Session.count }.by(1)
         | 
| 166 166 | 
             
            end
         | 
| @@ -176,3 +176,8 @@ method on the asserted object. | |
| 176 176 | 
             
            ```ruby
         | 
| 177 177 | 
             
            assert_empty? object_responding_to_empty_question_mark
         | 
| 178 178 | 
             
            ```
         | 
| 179 | 
            +
             | 
| 180 | 
            +
            ### Stubs & Mocks
         | 
| 181 | 
            +
             | 
| 182 | 
            +
            To write stubs and mocks in xUnit fashion, use `stub` instead of `allow` and
         | 
| 183 | 
            +
            `mock` instead of `expect`. Everything else is the same.
         | 
| @@ -9,11 +9,11 @@ module RSpec | |
| 9 9 | 
             
                    # Assertion match converts RSpec matchers into an XUnit friendly
         | 
| 10 10 | 
             
                    # assertions.
         | 
| 11 11 | 
             
                    #
         | 
| 12 | 
            -
                    # For example | 
| 13 | 
            -
                    # behaving in the same way as:
         | 
| 12 | 
            +
                    # For example, `assertion_match :eq` will create two methods:
         | 
| 14 13 | 
             
                    #
         | 
| 15 | 
            -
                    # `expect(action).to eq(expected)`
         | 
| 16 | 
            -
                     | 
| 14 | 
            +
                    # - `assert_eq` roughly `expect(action).to eq(expected)`
         | 
| 15 | 
            +
                    # - `assert_not_eq` roughly `expect(action).to_not eq(expected)`
         | 
| 16 | 
            +
                    def assertion_match(matcher, suffix = matcher)
         | 
| 17 17 | 
             
                      define_method "assert_#{suffix}" do |value, *args, &block|
         | 
| 18 18 | 
             
                        begin
         | 
| 19 19 | 
             
                          expect(value).to send(matcher, *args, &block)
         | 
| @@ -21,16 +21,25 @@ module RSpec | |
| 21 21 | 
             
                          raise e, e.message, adjust_for_better_failure_message(e.backtrace), cause: nil
         | 
| 22 22 | 
             
                        end
         | 
| 23 23 | 
             
                      end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                      define_method "assert_not_#{suffix}" do |value, *args, &block|
         | 
| 26 | 
            +
                        begin
         | 
| 27 | 
            +
                          expect(value).to_not send(matcher, *args, &block)
         | 
| 28 | 
            +
                        rescue Expectations::ExpectationNotMetError => e
         | 
| 29 | 
            +
                          raise e, e.message, adjust_for_better_failure_message(e.backtrace), cause: nil
         | 
| 30 | 
            +
                        end
         | 
| 31 | 
            +
                      end
         | 
| 24 32 | 
             
                    end
         | 
| 25 33 |  | 
| 26 34 | 
             
                    # Assertion match block converts RSpec block matchers into XUnit
         | 
| 27 35 | 
             
                    # friendly assertions.
         | 
| 28 36 | 
             
                    #
         | 
| 29 | 
            -
                    # For example | 
| 30 | 
            -
                    #  | 
| 37 | 
            +
                    # For example, `assertion_match_block :raises, :raise_error` will
         | 
| 38 | 
            +
                    # generate two methods:
         | 
| 31 39 | 
             
                    #
         | 
| 32 | 
            -
                    # `expect { bloc }.to raise_error`
         | 
| 33 | 
            -
                     | 
| 40 | 
            +
                    # - `assert_raises` roughly `expect { bloc }.to raise_error`
         | 
| 41 | 
            +
                    # - `assert_not_raises` roughly `expect { bloc }.to_not raise_error`
         | 
| 42 | 
            +
                    def assertion_match_block(matcher, suffix = matcher)
         | 
| 34 43 | 
             
                      define_method "assert_#{suffix}" do |*args, &block|
         | 
| 35 44 | 
             
                        begin
         | 
| 36 45 | 
             
                          expect(&block).to send(matcher, *args)
         | 
| @@ -38,75 +47,84 @@ module RSpec | |
| 38 47 | 
             
                          raise e, e.message, adjust_for_better_failure_message(e.backtrace), cause: nil
         | 
| 39 48 | 
             
                        end
         | 
| 40 49 | 
             
                      end
         | 
| 41 | 
            -
                    end
         | 
| 42 | 
            -
             | 
| 43 | 
            -
                    private
         | 
| 44 | 
            -
             | 
| 45 | 
            -
                    MATCHER_CRUFT_REGEX = /((?:be_)|(?:have_))(.*)/.freeze
         | 
| 46 50 |  | 
| 47 | 
            -
             | 
| 48 | 
            -
             | 
| 49 | 
            -
             | 
| 50 | 
            -
             | 
| 51 | 
            +
                      define_method "assert_not_#{suffix}" do |*args, &block|
         | 
| 52 | 
            +
                        begin
         | 
| 53 | 
            +
                          expect(&block).to_not send(matcher, *args)
         | 
| 54 | 
            +
                        rescue Expectations::ExpectationNotMetError => e
         | 
| 55 | 
            +
                          raise e, e.message, adjust_for_better_failure_message(e.backtrace), cause: nil
         | 
| 56 | 
            +
                        end
         | 
| 57 | 
            +
                      end
         | 
| 51 58 | 
             
                    end
         | 
| 52 59 | 
             
                  end
         | 
| 53 60 |  | 
| 54 | 
            -
                   | 
| 55 | 
            -
                  assertion_match : | 
| 56 | 
            -
                  assertion_match : | 
| 57 | 
            -
                  assertion_match : | 
| 58 | 
            -
                  assertion_match :be_a
         | 
| 61 | 
            +
                  # Useful aliaises.
         | 
| 62 | 
            +
                  assertion_match :be_truthy, :truthy
         | 
| 63 | 
            +
                  assertion_match :be_falsy, :falsy
         | 
| 64 | 
            +
                  assertion_match :be_nil, :nil
         | 
| 59 65 | 
             
                  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 | 
            -
             | 
| 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
         | 
| 66 | 
            +
                  assertion_match :be_kind_of, :kind_of
         | 
| 67 | 
            +
                  assertion_match :be_instance_of, :instance_of
         | 
| 68 | 
            +
                  assertion_match :be_between, :between
         | 
| 69 | 
            +
                  assertion_match :be_within, :within
         | 
| 70 | 
            +
             | 
| 87 71 | 
             
                  assertion_match_block :raise_error, :raise
         | 
| 88 72 | 
             
                  assertion_match_block :raise_error, :raises
         | 
| 89 | 
            -
             | 
| 73 | 
            +
             | 
| 74 | 
            +
                  # Exceptions to the block matcher rule.
         | 
| 75 | 
            +
                  assertion_match :satisfy
         | 
| 90 76 |  | 
| 91 77 | 
             
                  # Assert is an alias to `expect`. Use it when all else fails or doesn't
         | 
| 92 78 | 
             
                  # feel right. The `change` assertion with a block is a good example:
         | 
| 93 79 | 
             
                  #
         | 
| 80 | 
            +
                  # `assert! { block }.to change { value }` or
         | 
| 94 81 | 
             
                  # `assert { block }.to change { value }`
         | 
| 95 | 
            -
                  def assert(value = Expectations::ExpectationTarget::UndefinedValue, &block)
         | 
| 82 | 
            +
                  def assert!(value = Expectations::ExpectationTarget::UndefinedValue, &block)
         | 
| 83 | 
            +
                    Expectations::ExpectationTarget.for(value, block)
         | 
| 84 | 
            +
                  end
         | 
| 85 | 
            +
             | 
| 86 | 
            +
                  alias assert assert!
         | 
| 87 | 
            +
             | 
| 88 | 
            +
                  # Mock is an XUnit alternative to the `expect` based mocking syntax.
         | 
| 89 | 
            +
                  #
         | 
| 90 | 
            +
                  # `mock(Post).to receive(:comments)`
         | 
| 91 | 
            +
                  def mock(value = Expectations::ExpectationTarget::UndefinedValue, &block)
         | 
| 96 92 | 
             
                    Expectations::ExpectationTarget.for(value, block)
         | 
| 97 93 | 
             
                  end
         | 
| 98 94 |  | 
| 95 | 
            +
                  # Stub is an XUnit alternative to the `allow` based mocking syntax.
         | 
| 96 | 
            +
                  def stub(target)
         | 
| 97 | 
            +
                    RSpec::Mocks::AllowanceTarget.new(target)
         | 
| 98 | 
            +
                  end
         | 
| 99 | 
            +
             | 
| 99 100 | 
             
                  private
         | 
| 100 101 |  | 
| 102 | 
            +
                  ASSERTION_REGEX = /^assert_(.*)$/.freeze
         | 
| 101 103 | 
             
                  ASSERTION_PREDICATE_REGEX = /^assert_(.*)\?$/.freeze
         | 
| 102 104 |  | 
| 103 105 | 
             
                  def method_missing(method, *args, &block)
         | 
| 104 | 
            -
                    ASSERTION_PREDICATE_REGEX.match(method.to_s) do |match|
         | 
| 106 | 
            +
                    return if ASSERTION_PREDICATE_REGEX.match(method.to_s) do |match|
         | 
| 105 107 | 
             
                      value = args.shift
         | 
| 106 108 | 
             
                      matcher = "be_#{match[1]}"
         | 
| 107 109 |  | 
| 108 110 | 
             
                      expect(value).to Matchers::BuiltIn::BePredicate.new(matcher, *args, &block)
         | 
| 109 | 
            -
                    end | 
| 111 | 
            +
                    end
         | 
| 112 | 
            +
             | 
| 113 | 
            +
                    return if ASSERTION_REGEX.match(method.to_s) do |match|
         | 
| 114 | 
            +
                      matcher = match[1]
         | 
| 115 | 
            +
             | 
| 116 | 
            +
                      RSpec::XUnit::Assertions.module_eval do
         | 
| 117 | 
            +
                        if block.nil?
         | 
| 118 | 
            +
                          assertion_match matcher
         | 
| 119 | 
            +
                        else
         | 
| 120 | 
            +
                          assertion_match_block matcher
         | 
| 121 | 
            +
                        end
         | 
| 122 | 
            +
                      end
         | 
| 123 | 
            +
             | 
| 124 | 
            +
                      send "assert_#{match[1]}", *args, &block
         | 
| 125 | 
            +
                    end
         | 
| 126 | 
            +
             | 
| 127 | 
            +
                    super
         | 
| 110 128 | 
             
                  end
         | 
| 111 129 |  | 
| 112 130 | 
             
                  def respond_to_missing?(method, *)
         | 
    
        data/lib/rspec/xunit/version.rb
    CHANGED
    
    
    
        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. | 
| 4 | 
            +
              version: 0.5.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:  | 
| 11 | 
            +
            date: 2020-03-08 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: rspec-core
         |