Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verbose test syntax #42

Merged
merged 2 commits into from
Jun 13, 2017

Conversation

aliaksandr-martsinovich
Copy link
Contributor

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 #41 (and in fact includes it - I didn't know how to avoid this)

@sue445 sue445 requested a review from joker1007 June 10, 2017 16:40
@joker1007
Copy link
Collaborator

LGTM! Thanks!

@sue445
Copy link
Collaborator

sue445 commented Jun 13, 2017

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

aliaksandr-martsinovich@a3f3f64#commitcomment-22476673

other is LGTM

@aliaksandr-martsinovich
Copy link
Contributor Author

@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 sue445 merged commit 16b9fa9 into tomykaira:master Jun 13, 2017
@sue445
Copy link
Collaborator

sue445 commented Jun 13, 2017

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

@sue445
Copy link
Collaborator

sue445 commented Jun 13, 2017

@aliaksandr-martsinovich Released v0.4.0 💎

Thank you for your contribution!

@aliaksandr-martsinovich aliaksandr-martsinovich deleted the verbose_test_syntax branch June 13, 2017 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants