Permalink
Browse files

+ Acceptance specs to run examples in example/ folder and match again…

…st expected output
  • Loading branch information...
1 parent 3dfadfa commit 01f1232d8b7ba8a900dcc5eff0f3948f1a886921 @txus txus committed Feb 28, 2011
Showing with 29 additions and 0 deletions.
  1. +29 −0 spec/acceptance/examples_spec.rb
@@ -0,0 +1,29 @@
+require 'spec_helper'
+require 'open3'
+
+describe "Regression examples from example/ directory" do
+
+ Dir["example/*.rb"].each do |example|
+
+ it "parses #{example} successfully" do
+ stdin, stdout, stderr = Open3.popen3("ruby #{example}")
+
+ expected_output_file = example.gsub('.rb', '.out').gsub('example/','example/output/')
+ expected_error_file = example.gsub('.rb', '.err').gsub('example/','example/output/')
+
+ if File.exists?(expected_output_file)
+
+ stdout.readlines.join.strip.should include(File.read(expected_output_file).strip)
+
+ elsif File.exists?(expected_error_file)
+ stderr.readlines.join.strip.should include(File.read(expected_error_file).strip)
+ else
+ error = "Neither #{expected_output_file} nor #{expected_error_file} exists. Cannot compare results with any output or error."
+ fail error
+ end
+
+ end
+
+ end
+
+end

0 comments on commit 01f1232

Please sign in to comment.