Skip to content

Instantly share code, notes, and snippets.

@lorn
Created January 11, 2012 15:12
Show Gist options
  • Save lorn/1595115 to your computer and use it in GitHub Desktop.
Save lorn/1595115 to your computer and use it in GitHub Desktop.
Moose test
http://showmetheco.de/articles/2011/11/tdd-best-practices-in-perl.html
15:54 <@sartak> Test::Class is alright but check out Test::Routine too
15:54 <@mst> Lorn: I use Test::More
15:56 < Lorn> also, what is the address of Moose mailling list? moose.perl.org is out and I only find nntp list for moose
15:57 <@mst> [email protected]
15:57 < Lorn> Thanks
15:58 <@mst> Lorn: define "is out"
15:58 <@mst> Lorn: I got a redirect to moose.iinteractive.com
16:00 -!- KjetilK [[email protected]] has quit [Remote host closed the connection]
16:01 -!- daxim [[email protected]] has quit [Quit: pro quo, Agent Starling]
16:01 < Lorn> mst: Here in Brazil i got this: curl -i http://moose.perl.org
16:01 < Lorn> curl: (56) Failure when receiving data from the peer
16:02 <@sartak> I get a 302
16:02 <@sartak> looks like the problem is on your end :/
16:02 <@mst> actually, I think I know what it is
16:03 <@mst> duff AAAA record from a v6 tunnel that died
16:03 <@mst> combine that with a retarded ISP (it's brazil, that can be assumed) ...
16:04 -!- KjetilK [[email protected]] has joined #moose
16:04 < Lorn> haha
16:05 < Lorn> another test question, how can I create a mock with Moose/Moose::Role?
16:06 <@mst> look at Mock::Quick
16:06 <@mst> but bear in mind that needing very many mock objects indicates you're doing it wrong
16:08 -!- skington [[email protected]] has joined #moose
16:10 < Lorn> mst: true, i was reading about it these days and a guy cited you in a comment about test/mock - http://showmetheco.de/articles/2011/11/tdd-best-practices-in-perl.html#comment-361089090
16:13 < Mithaldu> Lorn: hi :)
16:14 < Lorn> Mithaldu: :D
16:16 < Mithaldu> i should write a blog post about this sometime
16:16 < Mithaldu> "My testing LWP::UserAgent comes with a webserver built-in"
16:16 <@sartak> yeeuck, Mock::Quick's api is awful
16:17 <@mst> it's a lot less horrible than Test::MockObject
16:17 <@sartak> he got it mostly right by having control objects though
16:17 <@sartak> no argument there
16:18 < Mithaldu> hrm
16:19 < Mithaldu> so how do you define an attribute that contains a sub ref?
16:19 < Mithaldu> oh wait
16:19 <@rjbs> has some_code => (is => 'ro', isa => 'CodeRef');
16:19 < Mithaldu> rjbs: ha ha
16:19 < Mithaldu> i was looking at Mock::Quick :)
16:19 <@doy> Test::Magpie is pretty nice too
16:20 <@doy> although it looks at mocking in a different way
16:20 < Mithaldu> i still think Sub::Override is superior mocking :)
16:21 <@mst> people are obsessed with mocks I find
16:21 <@mst> generally I write
16:21 <@mst> { local *Some::Class::foo = sub { ... } <tests here> }
16:22 < Mithaldu> yeah, that
16:22 <+purl> Sure, that.
16:22 < Mithaldu> i understand the mocking thing though
16:22 < Mithaldu> it feels a lot more safe
16:22 < Mithaldu> (felt)
16:25 <@mst> my problem is it's a lot less immediately obvious what's going on
16:26 < Lorn> Someone of this modules i can define things like "in this mock object the method ->foo will be called 3 times and will return content { bar => quux }" ? sorry for odd/ugly question
16:26 <@mst> local *Some::Class::foo = sub { $foo_calls++; return { bar => 'quux' } };
16:26 <@mst> is($foo_class, 3, 'foo called 3 times');
16:27 -!- bluescreen [[email protected]] has quit [Remote host closed the connection]
16:27 < Mithaldu> mst: huh, interesting point
16:30 < Lorn> mst: thanks
16:30 <@mst> Lorn: note - the libraries can probably do it
16:30 <@mst> but I found they required just as many lines of code
16:30 <@mst> and made my tests less obvious
16:30 <@mst> I like my tests to be really obvious
16:31 <@mst> since test bugs are 10x worse than normal bugs
16:33 <@doy> Lorn: that's what Test::Magpie does
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment