Haim Ashkenazi
2010-Oct-25 07:09 UTC
[rspec-users] Need help to figure out why this expectation isn''t met.
Hi This is my first ruby script, so sorry if it''s trivial :) I have a should_receive expectation on :new which should work (and works on a simple test I wrote) but it doesn''t work in my case and I can''t figure out why. The source is on github (commit: 5197b763f391d6d358ca7bc5838375c9247271d8). The spec that doesn''t work is in spec/runsshlib/cli_spec.rb line 127 (currently commented out). Can someone pls help me figure out why the expectation doesn''t work? Thanks in advance Haim -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20101025/cf9db05e/attachment.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: PGP.sig Type: application/pgp-signature Size: 194 bytes Desc: This is a digitally signed message part URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20101025/cf9db05e/attachment.bin>
Haim Ashkenazi
2010-Oct-25 08:54 UTC
[rspec-users] Need help to figure out why this expectation isn''t met.
Hi I''m not sure if the URLs in the original post can be viewed :( so here they are: The repository is here: http://github.com/babysnakes/runssh The spec with the problem is http://github.com/babysnakes/runssh/blob/5197b763f391d6d358ca7bc5838375c9247271d8/spec/runsshlib/cli_spec.rb (line 127). Thanks Haim On Oct 25, 2010, at 9:09 AM, Haim Ashkenazi wrote:> Hi > > This is my first ruby script, so sorry if it''s trivial :) > > I have a should_receive expectation on :new which should work (and works on a simple test I wrote) but it doesn''t work in my case and I can''t figure out why. The source is on github (commit: 5197b763f391d6d358ca7bc5838375c9247271d8). The spec that doesn''t work is in spec/runsshlib/cli_spec.rb line 127 (currently commented out). > > Can someone pls help me figure out why the expectation doesn''t work? > > Thanks in advance > > Haim >Haim Ashkenazi Com-n-Sense Mobile: +972-52-6188488 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20101025/e6597cd6/attachment.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: PGP.sig Type: application/pgp-signature Size: 194 bytes Desc: This is a digitally signed message part URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20101025/e6597cd6/attachment.bin>
Chris Mear
2010-Oct-26 09:15 UTC
[rspec-users] Need help to figure out why this expectation isn''t met.
On 25 Oct 2010, at 09:54, Haim Ashkenazi wrote:> On Oct 25, 2010, at 9:09 AM, Haim Ashkenazi wrote: > >> Hi >> >> This is my first ruby script, so sorry if it''s trivial :) >> >> I have a should_receive expectation on :new which should work (and works on a simple test I wrote) but it doesn''t work in my case and I can''t figure out why. The source is on github (commit: 5197b763f391d6d358ca7bc5838375c9247271d8). The spec that doesn''t work is in spec/runsshlib/cli_spec.rb line 127 (currently commented out). >> >> Can someone pls help me figure out why the expectation doesn''t work? >> >> Thanks in advance >> >> Haim > > Hi > > I''m not sure if the URLs in the original post can be viewed :( so here they are: > > ? The repository is here: http://github.com/babysnakes/runssh > ? The spec with the problem is http://github.com/babysnakes/runssh/blob/5197b763f391d6d358ca7bc5838375c9247271d8/spec/runsshlib/cli_spec.rb (line 127). > > Thanks > > Haim >(Moved your reply inline.) The rescuing that you do in line 56 of CLI#run was obscuring the real error here: 1) The CLI interface when run with subcommand shell should correctly initialize SshBackend Failure/Error: cli.run host definition (cust2 => dc => somehost) doesn''t exist! # ./lib/runsshlib/config_file.rb:101:in `get_host'' # ./lib/runsshlib/cli.rb:228:in `run_shell'' # ./lib/runsshlib/cli.rb:54:in `call'' # ./lib/runsshlib/cli.rb:54:in `run'' # ./spec/runsshlib/cli_spec.rb:133 I found this by commenting out the lines where you rescue the exception and raise a Trollop error instead. So the example wasn''t even reaching the line in CLI#run_shell where you create the SshBackend, because it was failing on the get_host call (since the example uses dummy data). I got the example to pass by also mocking/stubbing the ConfigFile stored in @c, and stubbing its get_host method: http://github.com/chrismear/runssh/commit/87ca98a1429b975e00b87ffadbb0b4c81d849af8 If you want to mock everything outside of the CLI object in this spec, that''s one (not hugely elegant) way to do it. When you have problems like this, it''s helpful to dig down and find the exact place the error is occurring. Chris
Haim Ashkenazi
2010-Oct-26 13:34 UTC
[rspec-users] Need help to figure out why this expectation isn''t met.
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi Chris, On Oct 26, 2010, at 11:15 AM, Chris Mear wrote:> > On 25 Oct 2010, at 09:54, Haim Ashkenazi wrote: > >> On Oct 25, 2010, at 9:09 AM, Haim Ashkenazi wrote: >> >>> Hi >>> >>> This is my first ruby script, so sorry if it''s trivial :) >>> >>> I have a should_receive expectation on :new which should work (and works on a simple test I wrote) but it doesn''t work in my case and I can''t figure out why. The source is on github (commit: 5197b763f391d6d358ca7bc5838375c9247271d8). The spec that doesn''t work is in spec/runsshlib/cli_spec.rb line 127 (currently commented out). >>> >>> Can someone pls help me figure out why the expectation doesn''t work? >>> >>> Thanks in advance >>> >>> Haim >> >> Hi >> >> I''m not sure if the URLs in the original post can be viewed :( so here they are: >> >> ? The repository is here: http://github.com/babysnakes/runssh >> ? The spec with the problem is http://github.com/babysnakes/runssh/blob/5197b763f391d6d358ca7bc5838375c9247271d8/spec/runsshlib/cli_spec.rb (line 127). >> >> Thanks >> >> Haim >> > > (Moved your reply inline.) > > The rescuing that you do in line 56 of CLI#run was obscuring the real error here: > > 1) The CLI interface when run with subcommand shell should correctly initialize SshBackend > Failure/Error: cli.run > host definition (cust2 => dc => somehost) doesn''t exist! > # ./lib/runsshlib/config_file.rb:101:in `get_host'' > # ./lib/runsshlib/cli.rb:228:in `run_shell'' > # ./lib/runsshlib/cli.rb:54:in `call'' > # ./lib/runsshlib/cli.rb:54:in `run'' > # ./spec/runsshlib/cli_spec.rb:133 > > I found this by commenting out the lines where you rescue the exception and raise a Trollop error instead. > > So the example wasn''t even reaching the line in CLI#run_shell where you create the SshBackend, because it was failing on the get_host call (since the example uses dummy data). > > I got the example to pass by also mocking/stubbing the ConfigFile stored in @c, and stubbing its get_host method: > > http://github.com/chrismear/runssh/commit/87ca98a1429b975e00b87ffadbb0b4c81d849af8 > > If you want to mock everything outside of the CLI object in this spec, that''s one (not hugely elegant) way to do it. > > When you have problems like this, it''s helpful to dig down and find the exact place the error is occurring. > > ChrisWow, that was a stupid mistake. Thanks for the time, the good eye and the advice :) I actually don''t need to stub everything, I just had to fix the path to match the fixtures. Thanks Haim -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (Darwin) iEYEARECAAYFAkzG2PsACgkQhwMtGgRKzT1NsACeJ5MTWvcBCxqbPaHqGfy/QLuJ +G4AoJD2hLjZ/eguqJFCOTs96dIQEa9W =2UGK -----END PGP SIGNATURE-----