Skip to content

Instantly share code, notes, and snippets.

module Spec
module Matchers
class IncludeAll
attr_reader :expected_elements, :actual_elements, :extra_elements_in_actual, :extra_elements_in_expected
def initialize(expected_elements)
@expected_elements = expected_elements
end
def matches?(actual_elements)
@actual_elements = actual_elements
class Foo
def bar
"baz"
end
end
if __FILE__ == $0
require 'rubygems'
require 'spec'
class Views::Layouts::Application < Erector::Widget
def render
div :class => "header" do
text "header"
end
div :class => "body" do
inner_content
end
# app/views/hellos/erb.html.erb
# note the leading spaces - this makes it exactly the same number of bytes that erector outputs
<%- 1000.times do -%><%= render :partial => "simple" %><%- end -%>
# app/views/hellos/_simple.html.erb
<p><%= "hello world" %></p>
When /^I type "([^\"]*)" into the "([^\"]*)" rich text editor$/ do |description, iframe_id|
selenium.select_frame "id=#{iframe_id}"
selenium.type_keys "css=body", description
selenium.select_frame "relative=top"
end
def in_memory_database?
ENV["RAILS_ENV"] == "test" and
ENV["IN_MEMORY_DB"] and
Rails::Configuration.new.database_configuration['test-in-memory']['database'] == ':memory:'
end
$TESTING=true
if in_memory_database?
puts "connecting to in-memory database ..."
@zilkey
zilkey / data centric state machine.rb
Created July 24, 2009 06:17
Data-backed state machine example
=begin
See http://www.websequencediagrams.com/ for awesome diagrams. It has an api as well.
DSL-based state machine implementations make it hard to follow good coding practices, such as:
- keeping things DRY
- making sure that objects have single responsibility
- making sure that classes change at the same pace (open closed)
- making sure that classes only depend on classes that change less often than they do
# created by Peter Jaros and Jeff Dean
require "rubygems"
require "spec"
require "active_support"
module Weekdays
def advance_weekdays(days)
d = self
days.times do |day|
# This allows you to have namespaced models in fixjour
module Fixjour
class Builder
def name
@name ||= (@options[:as] || @klass.name.underscore).to_s.gsub("/", "_")
end
end
end
osascript -e "set Volume 10" && say "this will turn your volume on and say something"