When testing out a complex website, replicating the |open|/selenium/setup?fixtures=x| line would be painful!
So, Add a const at the beginning of the setup_controller in Selenium Plugin at
./vendor/plugins/selenium_on_rails/lib/controllers/selenium_controller.rb:
MY_FIXTURES = “table_a, table_b, table_câ€
Also alter #setup as so :
def setup
unless params.has_key? :keep_session
reset_session
@session_wiped = true
end
if params[:fixtures] == “all“
fixtures = PM_FIXTURES
end
fixtures ||= params[:fixtures].to_s
@loaded_fixtures = load_fixtures fixtures
render :file => view_path('setup.rhtml'), :layout => layout_path
end
New lines are 6-9, and the change on 10 from referencing params[] to the local var fixtures.
Then, use this in the selenese script :
|open|/selenium/setup?fixtures=all|
Isn’t that beautiful!??
Now I don’t have to endure copy-paste-age-break hell on my fixtures configuration.
Ahhh, Ruby is so nice!
This is Poison Control Week, Mar 19-25, 2006. Since Mr. Yuk was conceived in 1971, this makes it Mr. Yuk’s Birthday!
The Strategy Pattern really resolves to “composition” in practice. This OO technique says to take components that could change at runtime and encapsulate them in their own objects. The master-object is then “composed” of instances of the dependent clasess.
Example:
class Duck
def fly
puts ‘Flap Flap’
end
def quack
puts ‘Quack!’
end
end
d = <span class="constant">Duck.new
d.flap
d.quack
Produces:
Flap Flap Quack!
So now handle the en-user request to have ducks with different flap :
class FlapWings
def fly
puts ‘Flap Flap’
end
end
class FlapSoaring
def fly
puts ‘Soaring in the wind’
end
end
class Duck
def initialize (flapInstance)
@flapDelegate = flapInstance
end
def changeFlap(flapInstance)
@flapDelegate = flapInstance
end
def fly
@flapDelegate.fly
end
def quack
puts ‘Quack!’
end
end
mallard = Duck.new(FlapWings.new)
mallard.fly
mallard.quack
mallard.changeFlap(FlapSoaring.new)
mallard.fly
Now produces :
Flap Flap Quack! Soaring in the wind
This example looks trivial. The technique is powerful. Behold that in Java/C#, this requires a lot of effort including Inheritance and Interfaces.
Nice that Ruby allows this run-time change through duck-typing!!