diff options
author | Clement Ho <clemmakesapps@gmail.com> | 2017-08-15 14:25:08 +0000 |
---|---|---|
committer | Clement Ho <clemmakesapps@gmail.com> | 2017-08-15 14:25:08 +0000 |
commit | 35659da185e3c6ec2862884b4e9e19dd20445957 (patch) | |
tree | 4ce78341a0a0ea1c14249d41f70a060a5d39cc22 /doc/development/testing.md | |
parent | 1405bf844831bbaf8a7ffb1c516906b858bfdbb6 (diff) | |
parent | fe09c25d68a61c5874e9beb0f018c05a4d789d70 (diff) | |
download | gitlab-ce-fix-btn-alignment.tar.gz |
Merge branch 'master' into 'fix-btn-alignment'fix-btn-alignment
# Conflicts:
# app/views/projects/merge_requests/_nav_btns.html.haml
Diffstat (limited to 'doc/development/testing.md')
-rw-r--r-- | doc/development/testing.md | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/doc/development/testing.md b/doc/development/testing.md index c7eac3cf40c..efd56484b12 100644 --- a/doc/development/testing.md +++ b/doc/development/testing.md @@ -279,6 +279,43 @@ end - Avoid scenario titles that add no information, such as "successfully". - Avoid scenario titles that repeat the feature title. +### Table-based / Parameterized tests + +This style of testing is used to exercise one piece of code with a comprehensive +range of inputs. By specifying the test case once, alongside a table of inputs +and the expected output for each, your tests can be made easier to read and more +compact. + +We use the [rspec-parameterized](https://github.com/tomykaira/rspec-parameterized) +gem. A short example, using the table syntax and checking Ruby equality for a +range of inputs, might look like this: + +```ruby +describe "#==" do + using Rspec::Parameterized::TableSyntax + + let(:project1) { create(:project) } + let(:project2) { create(:project) } + where(:a, :b, :result) do + 1 | 1 | true + 1 | 2 | false + true | true | true + true | false | false + project1 | project1 | true + project2 | project2 | true + project 1 | project2 | false + end + + with_them do + it { expect(a == b).to eq(result) } + + it 'is isomorphic' do + expect(b == a).to eq(result) + end + end +end +``` + ### Matchers Custom matchers should be created to clarify the intent and/or hide the |