Permalink
Browse files

initial support for expect syntax based on Jay Fields' expectations l…

…ibrary
  • Loading branch information...
0 parents commit 30e3a53c4a99774fc8ae84d726925d2b99ebad43 @dchelimsky committed Oct 26, 2008
Showing with 261 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +5 −0 History.txt
  3. +13 −0 Manifest.txt
  4. +71 −0 README.txt
  5. +25 −0 Rakefile
  6. +5 −0 lib/rspec-extensions.rb
  7. +7 −0 lib/rspec-extensions/expectations.rb
  8. +10 −0 script/console
  9. +14 −0 script/destroy
  10. +14 −0 script/generate
  11. +71 −0 script/txt2html
  12. +4 −0 spec/helper.rb
  13. +18 −0 spec/rspec-extensions/expectations_spec.rb
  14. +2 −0 spec/spec.opts
@@ -0,0 +1,2 @@
+pkg
+doc
@@ -0,0 +1,5 @@
+== Development
+
+* 1 major enhancement:
+
+ * initial support for expect syntax based on Jay Fields' expectations library
@@ -0,0 +1,13 @@
+History.txt
+Manifest.txt
+README.txt
+Rakefile
+lib/rspec-extensions.rb
+lib/rspec-extensions/expectations.rb
+script/console
+script/destroy
+script/generate
+script/txt2html
+spec/helper.rb
+spec/rspec-extensions/expectations_spec.rb
+spec/spec.opts
@@ -0,0 +1,71 @@
+= rspec-extensions
+
+* http://github.com/dchelimsky/rspec-extensions
+
+== DESCRIPTION:
+
+Experimental features that may or may not end up in rspec proper someday. Use at your own risk and/or pleasure.
+
+== FEATURES:
+
+* expectations - rspec extension based on Jay Field's expectations library (http://expectations.rubyforge.org)
+
+ describe "addition" do
+ it "should return 3 for (2 + 1)" do
+ expect 3 do
+ 2 + 1
+ end
+ end
+ end
+
+== REQUIREMENTS:
+
+rspec >= 1.1.0
+
+== INSTALL:
+
+ (requires hoe)
+
+ git clone git://github.com/dchelimsky/rspec-extensions.git
+ cd rspec-extensions
+ rake gem
+ rake gem_install
+
+To use expectations with rspec:
+
+ require 'rspec-extensions/expectations'
+ describe ... do
+ include RspecExtensions::Expectations
+ end
+
+or - if you want to include them globally, do this in spec/spec_helper.rb
+
+ require 'rspec-extensions'
+ Spec::Runner.configure do |config|
+ config.include RspecExtensions::Expectations
+ end
+
+== LICENSE:
+
+(The MIT License)
+
+Copyright (c) 2008 David Chelimsky
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,25 @@
+%w[rubygems rake rake/clean fileutils hoe newgem rubigen].each { |f| require f }
+$:.unshift 'lib'
+require File.dirname(__FILE__) + '/lib/rspec-extensions'
+
+$hoe = Hoe.new('rspec-extensions', RspecExtensions::VERSION) do |p|
+ p.developer('David Chelimsky', 'dchelimsky@gmail.com')
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
+ p.rubyforge_name = p.name # TODO this is default value
+ p.extra_deps = [['rspec','>= 1.1.11']]
+ p.extra_dev_deps = [['newgem', ">= #{::Newgem::VERSION}"]]
+
+ p.spec_extras['rdoc_options'] = ['--main', Dir['README*'].first] # hopefully fixed in future hoe > 1.8
+ p.clean_globs |= %w[**/.DS_Store tmp *.log]
+ path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
+ p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
+ p.rsync_args = '-av --delete --ignore-errors'
+end
+
+require 'newgem/tasks' # load /tasks/*.rake
+require 'spec/rake/spectask'
+
+Spec::Rake::SpecTask.new do |t|
+ t.spec_opts = ['--options', 'spec/spec.opts']
+end
+
@@ -0,0 +1,5 @@
+module RspecExtensions
+ VERSION = '0.0.0'
+end
+
+require 'rspec-extensions/expectations'
@@ -0,0 +1,7 @@
+module RspecExtensions
+ module Expectations
+ def expect value
+ yield.should == value
+ end
+ end
+end
@@ -0,0 +1,10 @@
+#!/usr/bin/env ruby
+# File: script/console
+irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
+
+libs = " -r irb/completion"
+# Perhaps use a console_lib to store any extra methods I may want available in the cosole
+# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
+libs << " -r #{File.dirname(__FILE__) + '/../lib/rspec-extensions.rb'}"
+puts "Loading rspec-extensions gem"
+exec "#{irb} #{libs} --simple-prompt"
@@ -0,0 +1,14 @@
+#!/usr/bin/env ruby
+APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
+
+begin
+ require 'rubigen'
+rescue LoadError
+ require 'rubygems'
+ require 'rubigen'
+end
+require 'rubigen/scripts/destroy'
+
+ARGV.shift if ['--help', '-h'].include?(ARGV[0])
+RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
+RubiGen::Scripts::Destroy.new.run(ARGV)
@@ -0,0 +1,14 @@
+#!/usr/bin/env ruby
+APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
+
+begin
+ require 'rubigen'
+rescue LoadError
+ require 'rubygems'
+ require 'rubigen'
+end
+require 'rubigen/scripts/generate'
+
+ARGV.shift if ['--help', '-h'].include?(ARGV[0])
+RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
+RubiGen::Scripts::Generate.new.run(ARGV)
@@ -0,0 +1,71 @@
+#!/usr/bin/env ruby
+
+load File.dirname(__FILE__) + "/../Rakefile"
+require 'rubyforge'
+require 'redcloth'
+require 'syntax/convertors/html'
+require 'erb'
+
+download = "http://rubyforge.org/projects/#{$hoe.rubyforge_name}"
+version = $hoe.version
+
+def rubyforge_project_id
+ RubyForge.new.configure.autoconfig["group_ids"][$hoe.rubyforge_name]
+end
+
+class Fixnum
+ def ordinal
+ # teens
+ return 'th' if (10..19).include?(self % 100)
+ # others
+ case self % 10
+ when 1: return 'st'
+ when 2: return 'nd'
+ when 3: return 'rd'
+ else return 'th'
+ end
+ end
+end
+
+class Time
+ def pretty
+ return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
+ end
+end
+
+def convert_syntax(syntax, source)
+ return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
+end
+
+if ARGV.length >= 1
+ src, template = ARGV
+ template ||= File.join(File.dirname(__FILE__), '/../website/template.html.erb')
+else
+ puts("Usage: #{File.split($0).last} source.txt [template.html.erb] > output.html")
+ exit!
+end
+
+template = ERB.new(File.open(template).read)
+
+title = nil
+body = nil
+File.open(src) do |fsrc|
+ title_text = fsrc.readline
+ body_text_template = fsrc.read
+ body_text = ERB.new(body_text_template).result(binding)
+ syntax_items = []
+ body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</\1>!m){
+ ident = syntax_items.length
+ element, syntax, source = $1, $2, $3
+ syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
+ "syntax-temp-#{ident}"
+ }
+ title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
+ body = RedCloth.new(body_text).to_html
+ body.gsub!(%r!(?:<pre><code>)?syntax-temp-(\d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
+end
+stat = File.stat(src)
+created = stat.ctime
+modified = stat.mtime
+
+$stdout << template.result(binding)
@@ -0,0 +1,4 @@
+$:.unshift(File.join(File.dirname(__FILE__), *%w[.. lib]))
+
+require 'rspec-extensions'
+require 'spec'
@@ -0,0 +1,18 @@
+require File.join(File.dirname(__FILE__), %w[.. helper])
+
+describe "expect value" do
+ include RspecExtensions::Expectations
+ it "should work just like should ==" do
+ expect 3 do
+ 1 + 2
+ end
+ end
+
+ it "should fail just like should ==" do
+ lambda {
+ expect 3 do
+ 1 + 1
+ end
+ }.should raise_error(/expected: 3.*got: 2/m)
+ end
+end
@@ -0,0 +1,2 @@
+--colour
+--format nested

0 comments on commit 30e3a53

Please sign in to comment.