Permalink
Browse files

. reset for your tests

  • Loading branch information...
1 parent 9596c6d commit d968e2f8660bc036500dc141b5653431ab334f55 @kschiess committed Jun 3, 2010
Showing with 29 additions and 1 deletion.
  1. +8 −0 lib/floor_manager.rb
  2. +6 −0 lib/floor_manager/employee.rb
  3. +6 −1 lib/floor_manager/floor.rb
  4. +9 −0 spec/unit/floor_manager_spec.rb
View
@@ -16,6 +16,14 @@ def define(environment_name, &block)
def get(environment_name)
floors[environment_name]
end
+
+ # Resets all instances produced. Use this in after(:each).
+ #
+ def reset
+ @floors.values.each do |floor|
@floere

floere Jun 3, 2010

How about
@floors.each do |_, floor|
?

@kschiess

kschiess Jun 4, 2010

Owner

So you like the underscore-wiggly better? I actually had it that way for 2 seconds ;)

@floere

floere Jun 4, 2010

Heh.
I must be in Ruby speed mode, currently – the first thing I thought: "Man, that's an unnecessary temporary Array right there."

If it's not about performance: Code beauty over speed :)

@kschiess

kschiess Jun 4, 2010

Owner

I make a mental habit of not being in speed mode.

@floere

floere Jun 4, 2010

You'd be surprised how good structure and beautiful code often produces fast code :)
(Point I wanted to make at Euruko, but somehow didn't clearly make ;) )

@kschiess

kschiess Jun 4, 2010

Owner

And the inverse is also true: How a-priori fast code makes for bad structure.

@floere

floere Jun 4, 2010

So from this we can deduce:
I'd also add

  1. "Put the information where it belongs."
    1a. "To see where the information belongs, it is imperative you write well structured code"
    From all this we can deduce:
  • Well structured code lets you minimize Information flow (because if it is where it needs to be, it doesn't need to flow), and by accident also makes it fast. If you really need a fast application, the usual techniques apply: Analyze, Optimize, Nicely wrap.
@kschiess

kschiess Jun 4, 2010

Owner

It helps to be a lazy person like me – I don't remember 1 and 1a when I hack like I did here. BTW: I will start annotating everything I do on github as 'an experiment' - looks like I get more press that way ;)

And .. please don't look at this code here. Nothing to see here. Move along ;)

@floere

floere Jun 4, 2010

Same here :)
I was curious: "What could a program named 'floor manager' do?" Now, it is as obvious as it was before: It manages floors.

"Dear Miss Souza, could you reset the floor every friday night?"

@kschiess

kschiess Jun 4, 2010

Owner

It is also useful to create many AR model instances on the fly in your tests:

http://gist.github.com/425169

Where
FloorManager.get(:space).space

will build an in-memory object that has all these connections (copies, pools, hosts, person, ...)

Factory Girl on drugs.

@floere

floere Jun 4, 2010

Nice!

How about
one Pool, :name => :pool1 do
name 'pool1'
host.set :host
end
instead of
one :pool1, :class => Pool do
name 'pool1'
host.set :host
end
since the class doesn't seem so optional, the name, I could well imagine to be optional.
Just an idea of someone who hasn't looked at it as deeply.

@floere

floere Jun 4, 2010

Ok, the name is needed often as well – for referencing.

@floere

floere Jun 4, 2010

Interesting anyway:
How do you best write a DSL that describes graphs (connections and nodes)?

@kschiess

kschiess Jun 4, 2010

Owner

Mu. Lines and boxes are probably the best DSL for graphs I know of. But if we limit ourselves to text, I guess you need symbolic references (names) to be able to do something other than a forest. And you end up with something like this or yaml or .. dare I say the word .. XML?

The problem is the linearity of text. Why does text have to be left to right, top down? Text should be able to warp back onto itself. Think torusses, hypercubes and moebius strips. Such a canvas would be ideal for my new graph DSL, the one where you have to take the drug for reading it as well, not only for writing it.

Anyway, are we having fun yet?

@floere

floere Jun 4, 2010

|-------------------------|
|                         |
|        I do Love        |
|                         |
|                         |
|-------------------------|
             |
             |
|-------------------------|          |-------------------------|
|                         |          |                         |
|                         |          |                         |
|      The idea of        |--------->|  Having to take drugs   |
|                         |          |                         |
|                         |          |                         |
|-------------------------|          |-------------------------|
             |                                    |
|-------------------------|
|        To read          |                    C O   D      E
|-------------------------|

Ok, I only had a cup of tea, so not quite the hypercubes I tried to imagine.

Your code IS actually warping back onto itself, by use of symbols, which the aliens which reside at the center of the universe also call "wormholes".
The : notation is a form of incantation, think "stitches" to combine the two symbols in your DSL. If you check it out per object_id you will see that the two seemingly different symbols are actually one and the same: A wormhole.

So yeah, definitely having fun.

@kschiess

kschiess Jun 4, 2010

Owner

I'm thinking: His search engine works, now he's bored.

I am also having fun over here: http://github.com/kschiess/rooc and http://github.com/kschiess/parslet, though a different kind. Maybe look into that next? ;)

@kschiess

kschiess Jun 4, 2010

Owner

PS: The parser tree warping is almost the same kind of fun as this thing here (though more the comments on it than the thing itself).

@floere

floere Jun 4, 2010

Heh, I'm thinking the same thing ;)
(Not really, but gemifying something and battling against Java – the thing that is supposed to help – is not too much fun)

I'd love to look into rooc especially. But in turn I'd like to see you create a great game on the 11th :)

@kschiess

kschiess Jun 4, 2010

Owner

We'll see. I don't have much hopes for anything useful in 3h. I am feeling strangled by that limitation already.

@floere

floere Jun 4, 2010

Think Pong, not Unreal Tournament 2010. That helped me.

Inspiration: http://github.com/severin/tree_run

+ floor.reset
+ end
+ end
end
end
@@ -47,6 +47,8 @@ def create(floor)
i.save! }
end
+ def reset
+ end
protected
def produce_instance
@klass_name.to_s.
@@ -82,6 +84,10 @@ def create(floor)
@instance
end
+
+ def reset
+ @instance = nil
+ end
end
# A template for employees, you can call build/create many times.
@@ -24,7 +24,6 @@ def object
@floor
end
end
-
def self.from_dsl(&block)
DSL.new(&block).object
end
@@ -48,4 +47,10 @@ def create(something)
def build(something)
employees[something.to_sym].build(self)
end
+
+ def reset
+ employees.values.each do |employee|
+ employee.reset
+ end
+ end
end
@@ -58,6 +58,15 @@
end
it { should be_saved }
end
+ context "after a reset" do
+ before(:each) {
+ @old_white = white
+ FloorManager.reset }
+
+ it "should produce a new white spy (forget about white)" do
+ @old_white.should_not == env.white
+ end
+ end
end
end

0 comments on commit d968e2f

Please sign in to comment.