Skip to content

Integrate test env - #2

Merged
stefan-as merged 3 commits into
developfrom
feature/tests
Mar 27, 2018
Merged

Integrate test env#2
stefan-as merged 3 commits into
developfrom
feature/tests

Conversation

@stefan-as

Copy link
Copy Markdown
Contributor

No description provided.

@stefan-as
stefan-as requested a review from robbl-as March 22, 2018 19:43
Comment thread test/plugin_stub.rb
c.before { allow($stderr).to receive(:puts) }

# XXX: Sensu plugins run in the context of an at_exit handler. This prevents
# XXX: code-under-test from being run at the end of the rspec suite.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@robbl-as die ganze Veranstaltung hier ist Cargo-Code at its best. Ohne den Zirkus machen die Test-Runs komisches Zeug, aber ich hab nicht im Ansatz begriffen, was hier passiert. Das ist zum einen sowieso schlecht, zum anderen würde ich gern die Gelegenheit nutzen und lernen. Weißt du, was hier abgeht? Kannst du es mir erklären?

Comment thread test/check-trello-incidents_spec.rb Outdated
stub_request(
:get,
'https://api.trello.com//1/lists/abcde/cards/?key=12345&token=12345'
).to_return(body: '[]', status: 200)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stefan-as Yeah ... Das sieht ja immer besser aus :)

Jetzt kannst du auch noch Expectations auf dem Stub ausführen und zwar nachdem die Aktion ausgeführt wurde, womit du dann das Arrange-Act-Assert-Prinzip einhalten kannst. Schau mal hier: https://github.com/bblimke/webmock#setting-expectations-in-rspec-on-the-stub

Comment thread test/check-trello-incidents_spec.rb Outdated
check.config[:list] = 'abcde'
expect(-> { check.run }).to raise_error Net::HTTPServerException

expect(check).to receive(:output).with('No new incidents')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stefan-as Und auch hier kannst du die Assertion erst nach der Aktion machen, indem du allow(check).to receive(:output) und expect(check).to have_received(:output).with('No new incidents') benutzt. Ref: https://relishapp.com/rspec/rspec-mocks/v/3-7/docs/basics/allowing-messages

PS: RSpec checkt hier sogar für dich, dass die Methode, die du mit allow stubst auch existiert. Solltest du also irgendwann die Methode umbenennen, fällt der Test um und du stubst nicht eine nicht existierende Methode.

Comment thread test/check-trello-incidents_spec.rb Outdated
expect(-> { check.run }).to raise_error Net::HTTPServerException

expect(check).to receive(:output).with('No new incidents')
expect(-> { check.run }).to raise_error SystemExit

@aboutNisblee aboutNisblee Mar 23, 2018

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stefan-as Und hier kannst du dir das Lambda auch sparen, da expect auch direkt nen Block frisst.

expect { check.run }.to raise_error(SystemExit)

@stefan-as

Copy link
Copy Markdown
Contributor Author

@aboutNisblee hab deine Vorschläge eingearbeitet. Über eine Erklärung zu diesem plugin_stub.rb würde ich mich noch freuen. Ich hab aber auch langsam eine Ahnung, was da passiert.

@stefan-as
stefan-as merged commit aa6123b into develop Mar 27, 2018
@stefan-as
stefan-as deleted the feature/tests branch March 27, 2018 11:40
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.

2 participants