tomykaira / rspec-parameterized

RSpec::Parameterized supports simple parameterized test syntax in rspec.
MIT License
417 stars 28 forks source link

Verbose test syntax #42

Closed aliaksandr-martsinovich closed 7 years ago

aliaksandr-martsinovich commented 7 years ago

Context: I'm using rspec for high-level integration tests and they very often carry a lot of verbose input arguments (such as hashes or arrays). For those cases I found it very convenient to represent tests as a hash of hashes:

describe "Verbose syntax" do
  where do
    {
        "positive integers" => {
            a: 1,
            b: 2,
            answer: 3,
        },
        "negative_integers" => {
            a: -1,
            b: -2,
            answer: -3,
        },
        "mixed_integers" => {
            a: 3,
            b: -3,
            answer: 0,
        },
    }
  end

  with_them do
    it "should do additions" do
      expect(a + b).to eq answer
    end
  end
end

or if you want some (almost) actual usage example:

where do
      {
          'the mots simple combinations of settings' => {
              settings: {
                  'my_user_1' => 'none',
                  'my_user_2' => 'none'
              },
              outcome: %w(my_user_1 my_user_2)
          },
          'a little bit more interesting case' => {
              settings: {
                  'my_user_1' => 'mode1',
                  'my_user_2' => 'none'
              },
              outcome: %w(my_user_1 my_user_2 my_user_3)
          },
          'a case with more users' => {
              settings: {
                  'my_user_1' => 'mode2',
                  'my_user_2' => 'none',
                  'my_user_3' => 'none',
                  'my_user_4' => 'none'
              },
              outcome: %w(my_user_1 my_user_2 my_user_3)
          },
          'more stuff' => {
              settings: {
                  'my_user_1' => 'mode3',
                  'my_user_2' => 'none',
                  'my_user_3' => 'none',
                  'my_user_4' => 'none'
              },
              outcome: %w(my_user_1 my_user_2 my_user_3)
          },
          'even more stuff' => {
              settings: {
                  'my_user_1' => 'mode3',
                  'my_user_2' => 'none',
                  'my_user_3' => 'none',
                  'my_user_4' => 'mode2',
                  'my_user_5' => 'none'
              },
              outcome: %w(my_user_1 my_user_2 my_user_3 my_user_4)
          },
          'last case' => {
              settings: {
                  'my_user_1' => 'mode3',
                  'my_user_2' => 'none',
                  'my_user_3' => 'none',
                  'my_user_4' => 'mode3',
                  'my_user_5' => 'none'
              },
              outcome: %w(my_user_1 my_user_2 my_user_3 my_user_4 my_user_5)
          }
      }
    end

Note that this feature depends on https://github.com/tomykaira/rspec-parameterized/pull/41 (and in fact includes it - I didn't know how to avoid this)

joker1007 commented 7 years ago

LGTM! Thanks!

sue445 commented 7 years ago

@aliaksandr-martsinovich #41 is merged. Please rebase and fix 4 spaces indent

https://github.com/aliaksandr-martsinovich/rspec-parameterized/commit/a3f3f6479ef9b3cdbb0a82ad76d1e3a232eee0e5#commitcomment-22476673

other is LGTM

aliaksandr-martsinovich commented 7 years ago

@sue445 Should be ok now. Thank you guys for the quick review! I'd also be very happy if you release the new gem version after merging this :)

sue445 commented 7 years ago

@aliaksandr-martsinovich LGTM I'll release gem soon!

sue445 commented 7 years ago

@aliaksandr-martsinovich Released v0.4.0 💎

Thank you for your contribution!