Gabi,
thanks for sharing. Nice start.
I just add link to more documentation where you can find more advanced
topics like dynamic response basic on arguments, expectation of calling
or redirect to original method.
http://rubydoc.info/gems/rspec-mocks/frames
Josef
On Mon, 23 Sep 2013 14:45:27 +0200
Gabriele Mohr
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Hi,
at the work shop we decided to use RSpec as the testing framework and I started to write spec-files for the YaST Fcoe Client.
The task was to create tests for a method which calls some methods reading from system files or getting hardware info. So for the test I need return values set for these methods. This is done by using stubs.
Tested method is FcoeClient::DetectNetworkCards which calls e.g. GetVlanInterfaces and GetFcoeStatus.
Examples for stubs of called methods:
@test_class.stub(:GetFcoeStatus).with("eth1.300", "eth1").and_return({})
@test_class.stub(:GetVlanInterfaces).and_return({ "eth1" => [{ "vlan" => "400", "fcf" => "00:0d:ec:a2:ef:00" }, { "vlan" => "300", "fcf" => "00:0d:ec:a2:ef:01" }], "eth2" => [{ "vlan" => "200", "fcf" => "00:0d:ec:a2:ef:02" }]})
The complete spec-file DetectNetworkCards_spec.rb is attached.
Complete yast-fcoe-client on https://github.com/yast/yast-fcoe-client.
Greetings Gabi
- -- Gabriele Mohr SUSE LINUX Products GmbH, GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer, HRB 16746 (AG Nürnberg) Maxfeldstr. 5 Tel: +49 911 740 53 362 90409 Nürnberg Email: gs@suse.de - ----------------------------------------------------------------- -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
iD8DBQFSQDfnzwhO63ql6h0RArbsAKCFMX3xIqgETzgLkEsB9nlFsrl1YACfVPDE ijio8fhWxfklP66+mAvinFw= =cIeA -----END PGP SIGNATURE-----
-- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org To contact the owner, e-mail: yast-devel+owner@opensuse.org