diff options
author | Louise Crow <louise.crow@gmail.com> | 2011-02-24 15:10:14 +0000 |
---|---|---|
committer | Louise Crow <louise.crow@gmail.com> | 2011-02-24 15:10:14 +0000 |
commit | 08a64f9e3139851fd65c7ba6969ee590b4afea6a (patch) | |
tree | 20c77e796002dfa95b2af3ba00ebd2f691c02fc7 /vendor/gems/rspec-1.3.1/features/support | |
parent | 3757bb52c0aa86b779b00428d7ebe35b30cea1ee (diff) |
Adding rspec gem.
Diffstat (limited to 'vendor/gems/rspec-1.3.1/features/support')
-rw-r--r-- | vendor/gems/rspec-1.3.1/features/support/env.rb | 83 | ||||
-rw-r--r-- | vendor/gems/rspec-1.3.1/features/support/matchers/smart_match.rb | 31 |
2 files changed, 114 insertions, 0 deletions
diff --git a/vendor/gems/rspec-1.3.1/features/support/env.rb b/vendor/gems/rspec-1.3.1/features/support/env.rb new file mode 100644 index 000000000..e649d82c5 --- /dev/null +++ b/vendor/gems/rspec-1.3.1/features/support/env.rb @@ -0,0 +1,83 @@ +$:.unshift File.join(File.dirname(__FILE__), "/../../lib") + +require 'spec/expectations' +require 'forwardable' +require 'tempfile' +require 'spec/ruby_forker' +require 'features/support/matchers/smart_match' +require 'spec/stubs/cucumber' + +class RspecWorld + include Spec::Expectations + include Spec::Matchers + include RubyForker + + extend Forwardable + def_delegators RspecWorld, :working_dir, :spec_command, :cmdline_file, :rspec_lib + + def self.working_dir + @working_dir ||= File.expand_path(File.join(File.dirname(__FILE__), "/../../tmp/cucumber-generated-files")) + end + + def self.spec_command + @spec_command ||= File.expand_path(File.join(File.dirname(__FILE__), "/../../bin/spec")) + end + + def self.cmdline_file + @cmdline_file ||= File.expand_path(File.join(File.dirname(__FILE__), "/../../resources/helpers/cmdline.rb")) + end + + def self.rspec_lib + @rspec_lib ||= File.join(working_dir, "/../../lib") + end + + def spec(args) + ruby("#{spec_command} #{args}") + end + + def cmdline(args) + ruby("#{cmdline_file} #{args}") + end + + def create_file(file_name, contents) + file_path = File.join(working_dir, file_name) + File.open(file_path, "w") { |f| f << contents } + end + + def create_directory(dirname) + FileUtils.mkdir_p File.join(working_dir, dirname) + end + + def last_stdout + @stdout + end + + def last_stderr + @stderr + end + + def last_exit_code + @exit_code + end + + # it seems like this, and the last_* methods, could be moved into RubyForker-- is that being used anywhere but the features? + def ruby(args) + stderr_file = Tempfile.new('rspec') + stderr_file.close + Dir.chdir(working_dir) do + @stdout = super("-I #{rspec_lib} #{args}", stderr_file.path) + end + @stderr = IO.read(stderr_file.path) + @exit_code = $?.to_i + end + +end + +Before do + FileUtils.rm_rf RspecWorld.working_dir if test ?d, RspecWorld.working_dir + FileUtils.mkdir_p RspecWorld.working_dir +end + +World do + RspecWorld.new +end diff --git a/vendor/gems/rspec-1.3.1/features/support/matchers/smart_match.rb b/vendor/gems/rspec-1.3.1/features/support/matchers/smart_match.rb new file mode 100644 index 000000000..7a6aa58a7 --- /dev/null +++ b/vendor/gems/rspec-1.3.1/features/support/matchers/smart_match.rb @@ -0,0 +1,31 @@ +Spec::Matchers.define :smart_match do |expected| + def regexp? + /^\/.*\/?$/ + end + + def quoted? + /^".*"$/ + end + + match do |actual| + case expected + when regexp? + actual =~ eval(expected) + when quoted? + actual.index(eval(expected)) + else # multi-line string + actual.index(expected) + end + end + + failure_message_for_should do |actual| + <<-MESSAGE +#{'*'*50} +got: +#{'*'*30} +#{actual} +#{'*'*50} +MESSAGE + end +end + |