buildr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject [4/5] buildr git commit: Makr the rspec dependency optional, except when actual rspec features used in buildfile.
Date Thu, 19 Feb 2015 23:38:18 GMT
Makr the rspec dependency optional, except when actual rspec features used in buildfile.

Update the buildr gemspec so that rspec is no longer a required dependency.
This enables end-users to use a different version of rspec and buildr in
the same project. The rspec version MUST be be compatible with the version
used by Buildr if rspec features are used from within Buildr. Buildr also
issues a warning if the `check` method is called and rspec has not been loaded.
The warning includes directions on how to resolve the issue. Submitted by r6p.


Project: http://git-wip-us.apache.org/repos/asf/buildr/repo
Commit: http://git-wip-us.apache.org/repos/asf/buildr/commit/10c17635
Tree: http://git-wip-us.apache.org/repos/asf/buildr/tree/10c17635
Diff: http://git-wip-us.apache.org/repos/asf/buildr/diff/10c17635

Branch: refs/heads/master
Commit: 10c176350aa836c27ff0a0f690cd3621ab14aec6
Parents: c3c859c
Author: Peter Donald <peter@realityforge.org>
Authored: Sat Feb 14 20:42:20 2015 +1100
Committer: Peter Donald <peter@realityforge.org>
Committed: Sat Feb 14 20:42:20 2015 +1100

----------------------------------------------------------------------
 CHANGELOG                      |  6 +++
 lib/buildr.rb                  |  2 +-
 lib/buildr/core/checks.rb      |  1 +
 lib/buildr/java/test_result.rb | 82 ++++++++++++++++++++-----------------
 lib/buildr/rspec_check.rb      | 51 +++++++++++++++++++++++
 5 files changed, 104 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/buildr/blob/10c17635/CHANGELOG
----------------------------------------------------------------------
diff --git a/CHANGELOG b/CHANGELOG
index 851d3f9..c7a382f 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,4 +1,10 @@
 1.4.22 (Pending)
+* Change: Update the buildr gemspec so that rspec is no longer a required dependency.
+          This enables end-users to use a different version of rspec and buildr in
+          the same project. The rspec version MUST be be compatible with the version
+          used by Buildr if rspec features are used from within Buildr. Buildr also
+          issues a warning if the `check` method is called and rspec has not been loaded.
+          The warning includes directions on how to resolve the issue. Submitted by r6p.
 * Fixed:  A long standing bug existed such that if tests failed to compile, and the
           option Buildr.options.test is set to :all then the compilation error would
           not result in a failed build. As many people set the Buildr.options.test to

http://git-wip-us.apache.org/repos/asf/buildr/blob/10c17635/lib/buildr.rb
----------------------------------------------------------------------
diff --git a/lib/buildr.rb b/lib/buildr.rb
index 669e386..b41a0c1 100644
--- a/lib/buildr.rb
+++ b/lib/buildr.rb
@@ -28,7 +28,6 @@ autoload :YAML, 'yaml'
 autoload :REXML, 'rexml/document'
 autoload :XmlSimple, 'xmlsimple'
 autoload :Builder, 'builder' # A different kind of buildr, one we use to create XML.
-autoload :RSpec, 'rspec'
 require 'erb'
 require 'find'
 require 'uri'
@@ -37,6 +36,7 @@ require 'fileutils'
 require 'orderedhash'
 require 'securerandom'
 
+require 'buildr/rspec_check'
 require 'buildr/core/util'
 require 'buildr/core/console'
 require 'buildr/core/common'

http://git-wip-us.apache.org/repos/asf/buildr/blob/10c17635/lib/buildr/core/checks.rb
----------------------------------------------------------------------
diff --git a/lib/buildr/core/checks.rb b/lib/buildr/core/checks.rb
index a695fef..78ebc6f 100644
--- a/lib/buildr/core/checks.rb
+++ b/lib/buildr/core/checks.rb
@@ -186,6 +186,7 @@ module Buildr #:nodoc:
     # During development you can write placeholder expectations by omitting the block. This
will simply report
     # the expectation as pending.
     def check(*args, &block)
+      Buildr.ensure_rspec('check() method invoked in buildfile')
       expectations << Checks::Expectation.new(*args, &block)
     end
 

http://git-wip-us.apache.org/repos/asf/buildr/blob/10c17635/lib/buildr/java/test_result.rb
----------------------------------------------------------------------
diff --git a/lib/buildr/java/test_result.rb b/lib/buildr/java/test_result.rb
index 3a8b608..979142c 100644
--- a/lib/buildr/java/test_result.rb
+++ b/lib/buildr/java/test_result.rb
@@ -15,7 +15,11 @@
 
 # It is necessary to require these files here as the bdd plugin directly includes this file
 require 'yaml'
-require 'rspec/core/formatters/base_formatter'
+begin
+  require 'rspec/core/formatters/base_formatter'
+rescue LoadError
+  # If Rspec is not present then assume we do no need Yaml formatter
+end
 
 module Buildr #:nodoc:
   module TestFramework #:nodoc:
@@ -52,49 +56,53 @@ module Buildr #:nodoc:
         @failed, @succeeded = [], []
       end
 
-      # An Rspec formatter used by buildr
-      class YamlFormatter  < ::RSpec::Core::Formatters::BaseFormatter
-        attr_reader :result
+      if Buildr.rspec_present?
+        require 'rspec/core/formatters/base_formatter'
 
-        def initialize(output)
-          super(output)
-          @result = Hash.new
-          @result[:succeeded] = []
-          @result[:failed] = []
-        end
+        # An Rspec formatter used by buildr
+        class YamlFormatter  < ::RSpec::Core::Formatters::BaseFormatter
+          attr_reader :result
 
-        def example_passed(example)
-          super(example)
-          result.succeeded << example_name(example)
-        end
+          def initialize(output)
+            super(output)
+            @result = Hash.new
+            @result[:succeeded] = []
+            @result[:failed] = []
+          end
 
-        def example_pending(example)
-          super(example)
-          result.succeeded << example_name(example)
-        end
+          def example_passed(example)
+            super(example)
+            result.succeeded << example_name(example)
+          end
 
-        def example_failed(example)
-          super(example)
-          result.failed << example_name(example)
-        end
+          def example_pending(example)
+            super(example)
+            result.succeeded << example_name(example)
+          end
 
-        def start(example_count)
-          super(example_count)
-          @result = TestResult.new
-        end
+          def example_failed(example)
+            super(example)
+            result.failed << example_name(example)
+          end
 
-        def close
-          super
-          result.succeeded = result.succeeded - result.failed
-          output.puts YAML.dump(result)
-        end
+          def start(example_count)
+            super(example_count)
+            @result = TestResult.new
+          end
 
-      private
-        def example_name(example)
-          example.file_path
-        end
-      end # YamlFormatter
+          def close
+            super
+            result.succeeded = result.succeeded - result.failed
+            output.puts YAML.dump(result)
+          end
+
+        private
+          def example_name(example)
+            example.file_path
+          end
+        end # YamlFormatter
 
-    end # TestResult
+      end # TestResult
+    end
   end
 end

http://git-wip-us.apache.org/repos/asf/buildr/blob/10c17635/lib/buildr/rspec_check.rb
----------------------------------------------------------------------
diff --git a/lib/buildr/rspec_check.rb b/lib/buildr/rspec_check.rb
new file mode 100644
index 0000000..7b178b8
--- /dev/null
+++ b/lib/buildr/rspec_check.rb
@@ -0,0 +1,51 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with this
+# work for additional information regarding copyright ownership.  The ASF
+# licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+module Buildr #:nodoc:
+
+  @@rspec_checked = false
+
+  def self.rspec_present?
+    unless @@rspec_checked
+      begin
+        require 'rspec'
+      rescue LoadError
+        # If Rspec is not present then that is ok
+      end
+      @@rspec_checked = true
+    end
+
+    $LOADED_FEATURES.any?{|f| f=~ /[\\\/]rspec\.rb$/ }
+  end
+
+  def self.ensure_rspec(context)
+    unless rspec_present?
+      # Has the rspec dependency been loaded?
+      message =
+        "#{context} but RSpec has not been loaded.\n" +
+          "\n" +
+          "Buildr prior to version 1.4.22, included rspec as a dependency but as\n" +
+          "of version 1.4.22, it is expected users manually add RSpec to their\n" +
+          "Gemfile. The following lines should be added to restore the version\n" +
+          "of rspec included in 1.4.22:\n" +
+          "\n" +
+          "gem 'rspec-expectations',   '= 2.14.3'\n" +
+          "gem 'rspec-mocks',          '= 2.14.3'\n" +
+          "gem 'rspec-core',           '= 2.14.5'\n" +
+          "gem 'rspec',                '= 2.14.1'\n"
+      fail message
+    end
+  end
+end


Mime
View raw message