tracks/vendor/plugins/rspec/lib/spec/story/step.rb
Luke Melia 35ae5fc431 Next step in upgrading Tracks to Rails 2.2. Some highlights:
* Ran rake rails:update
* Added old actionwebservice framework
* Updated RSpec and RSpec-Rails
* Removed asset_packager plugin (not compatible, Scott no longer maintaining), and replaced with bundle_fu. See the bundle_fu README for more info.
* Hacks to UJS and ARTS plugins, which are no longer supported. Probably should move off both UJS and RJS.
* Hack to flashobject_helper plugin (upgrade to Rails 2.2-compatible version if/when it comes out.)
* Hack to skinny-spec plugin, for Rails 2.2 compatibility. Should check for official release.
* Hacks to resource_feeder plugin, for Rails 2.2 compatibility. Should check for official release (not likely) or move off it.
* Addressed some deprecation warnings. More to come.
* My mobile mime type hackery is no longer necessary with new Rails features. Yay!
* Updated environment.rb.tmpl with changes

TODO:
* Restore view specs marked pending
* Fix failing integration tests.
* Try selenium tests.
* Investigate OpenID support.
* Address deprecation warnings.
* Consider moving parts of environment.rb to initializers
* Address annoying config.gem warning about highline gem
2008-11-30 00:34:15 -05:00

70 lines
1.7 KiB
Ruby

module Spec
module Story
class Step
PARAM_PATTERN = /([^\\]|^)(\$(?!\$)\w*)/
PARAM_OR_GROUP_PATTERN = /(\$(?!\$)\w*)|\(.*?\)/
attr_reader :name
def initialize(name, &block)
init_name(name)
init_expression(name)
block_given? ? init_module(name, &block) : set_pending
end
def perform(instance, *args)
raise Spec::Example::ExamplePendingError.new("Not Yet Implemented") if pending?
instance.extend(@mod)
instance.__send__(sanitize(@name), *args)
end
def matches?(name)
!(name.strip =~ @expression).nil?
end
def parse_args(name)
name.strip.match(@expression)[1..-1]
end
private
def sanitize(a_string_or_regexp)
return a_string_or_regexp.source if Regexp == a_string_or_regexp
a_string_or_regexp.to_s
end
def init_module(name, &block)
sanitized_name = sanitize(name)
@mod = Module.new do
define_method(sanitized_name, &block)
end
end
def set_pending
@pending = true
end
def pending?
@pending == true
end
def init_name(name)
@name = name
end
def init_expression(string_or_regexp)
if String === string_or_regexp
expression = string_or_regexp.dup
%w<? ( ) [ ] { } ^ !>.each {|c| expression.gsub! c, "\\#{c}"}
elsif Regexp === string_or_regexp
expression = string_or_regexp.source
end
while expression =~ PARAM_PATTERN
expression.sub!($2, "(.*?)")
end
@expression = Regexp.new("\\A#{expression}\\Z", Regexp::MULTILINE)
end
end
end
end