From: James Harrison Date: 2013-03-08T08:22:04+09:00 Subject: Re: Cannot Use Initialize With Minitest? --e89a8f22c5bd21128b04d75ddc8a Content-Type: text/plain; charset=ISO-8859-1 Hi folks, as an addendum, this problem is preset for me because I'm using minitest/autorun. I wanted to use this because of the various hooks that are provided (def setup() etc); if you can think of a way to provide the same pre-test hooks without being tied in to autorun, I could use that instead. Jams On Thu, Mar 7, 2013 at 4:02 PM, James Harrison wrote: > Hey folks, > > I've been trying my best to write a class that uses initialize() with > minitest, so that I can swap out a specific dependency at runtime. It > appears, though, that I cannot use initialize() in a class that inherits > from minitest: > > ##### > require "minitest/autorun" > > #A simple dependency which is being dispatched to. > class Dependency > def initialize(argument) > $stderr.puts argument > end > end > > #The main test class. > class TestProblemReproduction < MiniTest::Unit::TestCase > def initialize(test_argument) > Dependency.new(test_argument) > end > > def test_something > puts "This is here so minitest does something." > end > end > > > TestProblemReproduction.new("stuff") > > ####### > > Expected Output is to see the class Dependency output "stuff". > The actual output is that the class Dependency outputs > "stuff\ntest_something" > > > However, I have a use case where I would like to use minitest to run my > test cases, but I have a bunch of tests written in selenium. With one flag, > the selenium browser will be constructed to run locally on my desktop, for > local testing. With a different flag, the selenium browser is constructed > to run remotely on a set of remote test servers. > > Is there any way I can hand a dependency into my minitest based test > cases? Or do they have to be static? > > Thanks! > > Jams > --e89a8f22c5bd21128b04d75ddc8a Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hi folks,

as an addendum, this problem is preset for me = because I'm using minitest/autorun. I wanted to use this because of the= various hooks that are provided (def setup() etc); if you can think of a w= ay to provide the same pre-test hooks without being tied in to autorun, I c= ould use that instead.

Jams

On Thu, M= ar 7, 2013 at 4:02 PM, James Harrison <jam@jamandbees.net> = wrote:
Hey = folks,

I've been trying my best to write a class tha= t uses initialize() with minitest, so that I can swap out a specific depend= ency at runtime. It appears, though, that I cannot use initialize() in a cl= ass that inherits from minitest:

#####
require "minitest/autorun&quo= t;

#A simple dependency which is being dispatched = to.
class Dependency
=A0 def initialize(argument)
=A0 =A0 $stderr.puts argument
=A0 end
end

#The main test class.=A0
class TestProblemReprod= uction < MiniTest::Unit::TestCase
=A0 def initialize(test_argu= ment)
=A0 =A0 Dependency.new(test_argument)
=A0 end

=
=A0 def test_something
=A0 =A0 puts "This is here= so minitest does something."
=A0 end
end


TestProblemReproduction.new("stuff")

#######

Expected Outpu= t is to see the class Dependency output "stuff".
The ac= tual output is that the class Dependency outputs "stuff\ntest_somethin= g"


However, I have a use case where I= would like to use minitest to run my test cases, but I have a bunch of tes= ts written in selenium. With one flag, the selenium browser will be constru= cted to run locally on my desktop, for local testing. With a different flag= , the selenium browser is constructed to run remotely on a set of remote te= st servers.

Is there any way I can hand a dependency into my minite= st based test cases? Or do they have to be static?

Thanks!

Jams

--e89a8f22c5bd21128b04d75ddc8a--