Last active
October 16, 2017 08:22
-
-
Save igrep/bff4d45660055c566c24 to your computer and use it in GitHub Desktop.
RSpec 3.0から3.3まで一気に上げたので独断と偏見で選んだ注目すべき新機能を紹介する ref: http://qiita.com/igrep/items/cd1d2ba8ce5ccb6f5f44
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| RSpec.configure do |c| | |
| c.example_status_persistence_file_path = "./tmp/rspec-example-status.txt" | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| RSpec.describe Client do | |
| let(:response) { Client.make_request } | |
| it "returns a successful JSON response" do | |
| expect(response.status).to eq(200) | |
| expect(response.headers).to include("Content-Type" => "application/json") | |
| expect(response.body).to eq('{"message":"Success"}') | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| RSpec.describe Client do | |
| let(:response) { Client.make_request } | |
| it "returns a successful JSON response" do | |
| expect(response.status).to eq(200) | |
| expect(response.headers).to include("Content-Type" => "application/json") | |
| expect(response.body).to eq('{"message":"Success"}') | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| RSpec.describe Client do | |
| let(:response) { Client.make_request } | |
| it "returns a successful JSON response", :aggregate_failures do | |
| expect(response.status).to eq(200) | |
| expect(response.headers).to include("Content-Type" => "application/json") | |
| expect(response.body).to eq('{"message":"Success"}') | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| RSpec.describe Client do | |
| let(:response) { Client.make_request } | |
| it "returns a successful JSON response", :aggregate_failures do | |
| expect(response.status).to eq(200) | |
| expect(response.headers).to include("Content-Type" => "application/json") | |
| expect(response.body).to eq('{"message":"Success"}') | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| RSpec.configure do |c| | |
| c.define_derived_metadata do |meta| | |
| meta[:aggregate_failures] = true unless meta.key?(:aggregate_failures) | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| RSpec.configure do |c| | |
| c.define_derived_metadata do |meta| | |
| meta[:aggregate_failures] = true unless meta.key?(:aggregate_failures) | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # ここに書けばこのブロック内すべてのexampleが`aggregate_failures`されます。 | |
| RSpec.describe Client, aggregate_failures: false do | |
| let(:response) { Client.make_request } | |
| # もちろん個別に指定してもOK! | |
| it "returns a successful JSON response", aggregate_failures: false do | |
| expect(response.status).to eq(200) | |
| expect(response.headers).to include("Content-Type" => "application/json") | |
| expect(response.body).to eq('{"message":"Success"}') | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # ここに書けばこのブロック内すべてのexampleが`aggregate_failures`されます。 | |
| RSpec.describe Client, aggregate_failures: false do | |
| let(:response) { Client.make_request } | |
| # もちろん個別に指定してもOK! | |
| it "returns a successful JSON response", aggregate_failures: false do | |
| expect(response.status).to eq(200) | |
| expect(response.headers).to include("Content-Type" => "application/json") | |
| expect(response.body).to eq('{"message":"Success"}') | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| expect { subject_method }.to raise_error |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def just_hello | |
| puts "hello" | |
| frined.accept_hello_of(self) | |
| rescue Exception | |
| warn "I JUST WANT TO SAY HELLO!! DON'T DISTURB!!" | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| it 'says hello to no other person' do | |
| expect(friend).not_to receive(:accept_hello_of) | |
| x.just_hello | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment