#ruby - 04 October 2017
« Back 1 day Forward 1 day »
[00:42:20] RickHull: ycyclist: just curious, are you wedded to flexmock? it looks unmaintained (RIP Jim)
[00:47:17] ycyclist: Yes, I know. I am somewhat wedded, but the problem is known at large. Thank you.
[00:47:34] ycyclist: Interestingly, I got the case to work, but what I am stuck on now is a more general problem.
[00:48:57] ycyclist: I need to re-initialize the require step that is presently happening at the top of the file, inside each of several flexmock blocks where I am stubbing Socket.gethostname I can set a different value.
[00:50:01] ycyclist: flexmock(Socket,:strict,Socket => :gethostname, :gethostname => "myhostname") do hostname = Socket.gethostname assert_equal("myhostname", hostname, "Could not get the hostname")
[00:50:13] RickHull: hm, right off the bat, it is a smell that require would have "significant" side effects
[00:50:35] ycyclist: But as you can see, what I really need is to require the stuff all over again so that the stub gets used.
[00:52:02] ycyclist: There must be a way, especially for things like testing, to force a re-require.
[00:58:36] ycyclist: Sorry, I'm slow: https://gist.github.com/v-xecamp/2d5cf385975155137763f0a0052d3df5
[01:01:26] ycyclist: We require the class to the test script and then go through all the methods and test them. We often can get away with testin things without mocks, but this one would be really helpful.
[01:02:58] RickHull: so, are there any effects at requiretime besides loading classes/modules and their contained methods?
[01:03:13] ycyclist: This is a fairly simple test. Is Ruby seriously averse to reloading inside a block and ignoring what was there before?
[01:04:09] ycyclist: There are internal methods, but these are all Class methods, no instance available except to the extent that a Class is an object anyway.
[01:05:17] ycyclist: Thingy.method1 calls Socket.gethostname. It is defined inside MOD::Thingy. Pretty simple class really.
[01:06:19] RickHull: for example, I could define Thingy and method1, and then after the module/class definition, I could call it
[01:08:09] ycyclist: Yes, I want to require many times, in many different tests. Many is probably 2, but it is at least 2.
[01:08:42] ycyclist: Sometimes we get ip addresses back from Socket.gethostname. We want to handle that well.
[01:09:58] RickHull: I expect code declarations to be made, but no imperative code will be executed for "setup"
[01:10:15] ycyclist: The state that changes is I want the stubbed Socket.gethostname to be in effect when I re-load so that Thingy.method1, which uses it, will use the stub instead of the original.
[01:10:59] ycyclist: Right now, we stub Socket.gethostname, but because the stubbing happens after the definition of Thingy.method1, method1 just uses the original defintion of Socket.gethostname.
[01:11:41] ycyclist: Seems like this is a typical case for stubbing, except for the stinker of the fact that it's a Singleton and a class, not an instance object.
[01:12:10] ycyclist: But I got that part kindof fixed, except, I cannot pass an instance to the thing, I need to have it defined when the module definition occurs.
[01:13:06] ycyclist: All sorts of externalities could be moralized on here, but we're all human, and I like humans, so I'm working with it.
[01:14:04] ycyclist: Ok. That will be my starting point tomorrow. I fear right now my wife wants me to go home.
[01:14:56] RickHull: calling Socket stuff directly inside a singleton is a recipe for a testing headache
[01:15:22] RickHull: I have written tons of tests but nothing successfully with mocks or stubs; testability informs my program design
[01:16:16] ycyclist: Yes. I have always tried to avoid them if possible, but sometimes stubbing and mocking are good answers.
[01:17:05] RickHull: for sure, I wish I had better guidance here but I've avoided these problems somehow; I love your attitude though :)
[01:17:13] ycyclist: I'm already breaking down Thingy's insides to check on its pieces, so I have it pretty well covered, but we want this too, and we will probably use it for future exigencies.
[01:17:32] ycyclist: I suspect it's a good idea. I am really looking forward to migrating to minitest though. It is so much nicer.
[01:18:25] RickHull: 2. therefore, you may need to split out stuff that needs to be mocked (calls to Socket, etc)
[01:19:52] RickHull: however, there are some situations where you need to require some stuff before the mocks
[01:20:03] RickHull: and thats where you may need to consider splitting out the lib/source functionality
[01:23:16] RickHull: all that said, I am just making an educated guess. I don't know mocks and stubs very well
[07:01:16] Vap0r1ze: How do I define class methods, where the name of the method is based on a variable string
[12:48:19] vasilakisFiL: hey folks! I am wondering, doesn anyone know why self.private_method= doesn't raise an error bug self.private_method does? (snippet: https://gist.github.com/vasilakisfil/7eb19688f3861d9e1b54437c47c60f07 )
[12:49:07] matthewd: vasilakisfil: It's a special case, because private_method= without the self. wouldn't do the right thing
[12:52:41] vasilakisFiL: but that's inconsistend a bit. In any case, I would really like it if ruby could extend this special case to the self.foobar as well, so that we can access private accessor from inside our class seamlessly (in case we use a local variable of the same name)
[16:15:45] naftilos76: hi i am trying to extract a substring from a big string with "some_string".scan(//) . Assuming that there are two words in the big string "one" and "two" and i want to extract the substring between these two words what would be your approach?
[16:18:02] Papierkorb: naftilos76: Only one occurence of a one/two pair in one big string, or possibly multiple occurences?
[16:24:29] naftilos76: Papierkorb, i have an instance that contains a big string and i do this: @file_data[/^(.*)$/, 1] and i get an empty string. Is that what it should do?
[19:57:47] troulouliou_dev: hi what is the check_empty in this case : def valid?(value, check_empty: true)
[19:59:45] Papierkorb: troulouliou_dev: That's a key-word argument with a default value of `true`. To pass a different value to it, you have to explicitly pass the keyword name: `valid?(foo, check_empty: false)`. You can't omit the name, this won't work: `valid?(foo, false)`
[21:16:08] Rythen: Hi I'm new to Ruby. I was wondering if it's considered better form to use symbols or strings as keys in Ruby. Is one considered more right or is it just preference that varies from developer to developer?
[21:26:29] matthewd: Rythen: If it's all in straight code, symbols are handy. If you're using externally-input data, strings are more common.
[21:31:04] Rythen: matthewd: So if you were for example parsing strings and ptuting them into a hash it'd be better to keep the keys as strings since that's what they originally are?
[23:48:13] cagomez_: whats the preferred object creation pattern when you want to pass in a variable and immediately get a return value back? like a throwaway object that doesn't really need to hold any state, just generate a string (for example) based on the params
[23:52:17] cagomez_: one example i saw is SomeObject.call() where SomeObject had def self.call; new.call(); end; def cell; doStuff; end; end;