This patch makes some changes to support Ruby 2.0 and adds 2.0.0 to
1 | .travis.yml |
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | patch diff --git .travis.yml .travis.yml index 661dd2b..a3297f0 100644 --- .travis.yml +++ .travis.yml @@ -1,4 +1,5 @@ rvm: + - 2.0.0 - 1.9.3 - 1.9.2 diff --git cucumber.yml cucumber.yml index b081270..52e3727 100644 --- cucumber.yml +++ cucumber.yml @@ -15,6 +15,7 @@ jruby: --tags ~ --tags ~ jruby_win: --tags ~ --tags ~ CUCUMBER_FORWARD_SLASH_PATHS=true windows_mri: --tags ~ --tags ~ --tags ~ --tags ~-many-fonts CUCUMBER_FORWARD_SLASH_PATHS=true ruby_1_9: --tags ~ --tags ~ +ruby_2_0: --tags ~ --tags ~ wip: --tags :3 --wip features none: --format pretty rerun: --format rerun --out rerun.txt --strict --tags ~ diff --git fixtures/self_test/features/support/env.rb fixtures/self_test/features/support/env.rb index 1ce0d3a..2dc9ff5 100644 --- fixtures/self_test/features/support/env.rb +++ fixtures/self_test/features/support/env.rb @@ -1,6 +1,6 @@ require 'base64' begin require 'rspec/expectations'; rescue LoadError; require 'spec/expectations'; end -$KCODE = 'u' unless Cucumber::RUBY_1_9 +$KCODE = 'u' if Cucumber::RUBY_2_0 Before('') do raise "Should never run" diff --git gem_tasks/cucumber.rake gem_tasks/cucumber.rake index 2789906..8bcfc82 100644 --- gem_tasks/cucumber.rake +++ gem_tasks/cucumber.rake @@ -3,12 +3,14 @@ require 'cucumber/platform' class Cucumber::Rake::Task def set_profile_for_current_ruby - self.profile = if(Cucumber::JRUBY) + self.profile = if Cucumber::JRUBY Cucumber::WINDOWS ? 'jruby_win' : 'jruby' - elsif(Cucumber::WINDOWS_MRI) + elsif Cucumber::WINDOWS_MRI 'windows_mri' - elsif(Cucumber::RUBY_1_9) + elsif Cucumber::RUBY_1_9 'ruby_1_9' + elsif Cucumber::RUBY_2_0 + 'ruby_2_0' end end end diff --git legacy_features/support/env.rb legacy_features/support/env.rb index 8a3d848..a70afef 100644 --- legacy_features/support/env.rb +++ legacy_features/support/env.rb @@ -101,7 +101,7 @@ class CucumberWorld stderr_file = Tempfile.new('cucumber') stderr_file.close in_current_dir do - mode = Cucumber::RUBY_1_9 ? {:external_encoding=>"UTF-8"} : 'r' + mode = Cucumber::RUBY_1_8_7 ? 'r' : {:external_encoding=>"UTF-8"} IO.popen("#{command} 2> #{stderr_file.path}", mode) do |io| = io.read end diff --git lib/cucumber/core_ext/instance_exec.rb lib/cucumber/core_ext/instance_exec.rb index 0346a34..d76c21e 100644 --- lib/cucumber/core_ext/instance_exec.rb +++ lib/cucumber/core_ext/instance_exec.rb @@ -54,7 +54,7 @@ class Object #:nodoc: def cucumber_arity(block) a = block.arity - Cucumber::RUBY_1_9 ? a : (a == -1 ? 0 : a) + Cucumber::RUBY_1_8_7 ? (a == -1 ? 0 : a) : a end def cucumber_compatible_arity?(args, block) @@ -74,7 +74,7 @@ class Object #:nodoc: end end - INSTANCE_EXEC_OFFSET = (Cucumber::RUBY_1_9 || Cucumber::RUBY_1_8_7 || Cucumber::JRUBY) ? -3 : -4 + INSTANCE_EXEC_OFFSET = (Cucumber::RUBY_2_0 || Cucumber::RUBY_1_9 || Cucumber::RUBY_1_8_7 || Cucumber::JRUBY) ? -3 : -4 def replace_instance_exec_invocation_line!(backtrace, instance_exec_invocation_line, pseudo_method) return if Cucumber.use_full_backtrace diff --git lib/cucumber/formatter/unicode.rb lib/cucumber/formatter/unicode.rb index 61fe#..0105d5e 100644 --- lib/cucumber/formatter/unicode.rb +++ lib/cucumber/formatter/unicode.rb @@ -2,10 +2,10 @@ # Tips for improvement - esp. ruby 1.9: http://www.ruby-forum.com/topic/184730 require 'cucumber/platform' require 'cucumber/formatter/ansicolor' -$KCODE='u' unless Cucumber::RUBY_1_9 +$KCODE='u' if Cucumber::RUBY_2_0 if Cucumber::WINDOWS - require 'iconv' unless Cucumber::RUBY_1_9 + require 'iconv' if Cucumber::RUBY_2_0 if ENV['CUCUMBER_OUTPUT_ENCODING'] Cucumber::CODEPAGE = ENV['CUCUMBER_OUTPUT_ENCODING'] @@ -27,14 +27,7 @@ if Cucumber::WINDOWS o.instance_eval do alias cucumber_print print def print(*a) - if Cucumber::RUBY_1_9 - begin - cucumber_print(*a.map{|arg| arg.to_s.encode(Encoding.default_external)}) - rescue Encoding::UndefinedConversionError => e - STDERR.cucumber_puts("WARNING: #{e.message}") - cucumber_print(*a) - end - else + if Cucumber::RUBY_1_8_7 begin cucumber_print(*Iconv.iconv(Cucumber::CODEPAGE, "UTF-8", *a.map{|a|a.to_s})) rescue Iconv::InvalidEncoding => e @@ -44,19 +37,19 @@ if Cucumber::WINDOWS STDERR.cucumber_puts("WARNING: #{e.message}") cucumber_print(*a) end + else + begin + cucumber_print(*a.map{|arg| arg.to_s.encode(Encoding.default_external)}) + rescue Encoding::UndefinedConversionError => e + STDERR.cucumber_puts("WARNING: #{e.message}") + cucumber_print(*a) + end end end alias cucumber_puts puts def puts(*a) - if Cucumber::RUBY_1_9 - begin - cucumber_puts(*a.map{|arg| arg.to_s.encode(Encoding.default_external)}) - rescue Encoding::UndefinedConversionError => e - STDERR.cucumber_puts("WARNING: #{e.message}") - cucumber_puts(*a) - end - else + if Cucumber::RUBY_1_8_7 begin cucumber_puts(*Iconv.iconv(Cucumber::CODEPAGE, "UTF-8", *a.map{|a|a.to_s})) rescue Iconv::InvalidEncoding => e @@ -66,6 +59,13 @@ if Cucumber::WINDOWS STDERR.cucumber_puts("WARNING: #{e.message}") cucumber_puts(*a) end + else + begin + cucumber_puts(*a.map{|arg| arg.to_s.encode(Encoding.default_external)}) + rescue Encoding::UndefinedConversionError => e + STDERR.cucumber_puts("WARNING: #{e.message}") + cucumber_puts(*a) + end end end end diff --git lib/cucumber/platform.rb lib/cucumber/platform.rb index a71eea4..9b99f62 100644 --- lib/cucumber/platform.rb +++ lib/cucumber/platform.rb @@ -14,6 +14,7 @@ unless defined?(Cucumber::VERSION) WINDOWS_MRI = WINDOWS && !JRUBY && !IRONRUBY RAILS = defined?(Rails) RUBY_BINARY = File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name']) + RUBY_2_0 = RUBY_VERSION =~ /^2\.0/ RUBY_1_9 = RUBY_VERSION =~ /^1\.9/ RUBY_1_8_7 = RUBY_VERSION =~ /^1\.8\.7/ @@ -21,7 +22,7 @@ unless defined?(Cucumber::VERSION) attr_accessor :use_full_backtrace def file_mode(m, encoding="UTF-8") #:nodoc: - RUBY_1_9 ? "#{m}:#{encoding}" : m + RUBY_1_8_7 ? m : "#{m}:#{encoding}" end end self.use_full_backtrace = false diff --git lib/cucumber/rake/task.rb lib/cucumber/rake/task.rb index 6596c7f..c5583ec 100644 --- lib/cucumber/rake/task.rb +++ lib/cucumber/rake/task.rb @@ -143,7 +143,7 @@ module Cucumber # true, +fork+ is implicit. attr_accessor :rcov def rcov=(flag) - if(flag && Cucumber::RUBY_1_9) + if flag && !Cucumber::RUBY_1_8_7 raise failed + "RCov only works on Ruby 1.8.x. You may want to use SimpleCov: https://github.com/colszowka/simplecov" + reset end = flag diff --git spec/cucumber/cli/configuration_spec.rb spec/cucumber/cli/configuration_spec.rb index 88894ed..60293ae 100644 --- spec/cucumber/cli/configuration_spec.rb +++ spec/cucumber/cli/configuration_spec.rb @@ -8,9 +8,13 @@ module Cli attr_reader :options end + def convert_hash_to_yaml_erb(hash) + ["---", *hash.map { |k,v| "#{k}: #{v}" }].join "\n" + end + def given_cucumber_yml_defined_as(hash_or_string) File.stub!(:exist?).and_return(true) - cucumber_yml = hash_or_string.is_a?(Hash) ? hash_or_string.to_yaml : hash_or_string + cucumber_yml = hash_or_string.is_a?(Hash) ? convert_hash_to_yaml_erb(hash_or_string) : hash_or_string IO.stub!(:read).with('cucumber.yml').and_return(cucumber_yml) end diff --git spec/cucumber/core_ext/proc_spec.rb spec/cucumber/core_ext/proc_spec.rb index f5fcb48..fc9fc44 100644 --- spec/cucumber/core_ext/proc_spec.rb +++ spec/cucumber/core_ext/proc_spec.rb @@ -35,20 +35,20 @@ describe Proc do }.should raise_error(Cucumber::ArityMismatchError, "Your block takes 2 arguments, but the Regexp matched 1 argument.") end - if Cucumber::RUBY_1_9 - it "should allow varargs (expecting 0+)" do + if Cucumber::RUBY_1_8_7 + # Ruby 1.8 + it "should not allow varargs 0+ because Ruby 1.8 reports same arity as with no args, so we can't really tell the difference." do lambda { Object.new.cucumber_instance_exec(true, 'foo', 1) do |*args| end - }.should_not raise_error(Cucumber::ArityMismatchError) + }.should raise_error(Cucumber::ArityMismatchError, "Your block takes 0 arguments, but the Regexp matched 1 argument.") end else - # Ruby 1.8 - it "should not allow varargs 0+ because Ruby 1.8 reports same arity as with no args, so we can't really tell the difference." do + it "should allow varargs (expecting 0+)" do lambda { Object.new.cucumber_instance_exec(true, 'foo', 1) do |*args| end - }.should raise_error(Cucumber::ArityMismatchError, "Your block takes 0 arguments, but the Regexp matched 1 argument.") + }.should_not raise_error(Cucumber::ArityMismatchError) end end diff --git spec/cucumber/step_match_spec.rb spec/cucumber/step_match_spec.rb index fb42702..35ce644 100644 --- spec/cucumber/step_match_spec.rb +++ spec/cucumber/step_match_spec.rb @@ -7,7 +7,7 @@ module Cucumber describe StepMatch do include RSpec::WorkInProgress - WORD = Cucumber::RUBY_1_9 ? '[[:word:]]' : '\w' + WORD = Cucumber::RUBY_1_8_7 ? '\w' : '[[:word:]]' before do = RbSupport::RbLanguage.new(nil) diff --git spec/spec_helper.rb spec/spec_helper.rb index fe145ae..f7e773d 100644 --- spec/spec_helper.rb +++ spec/spec_helper.rb @@ -13,7 +13,7 @@ require 'bundler' Bundler.setup require 'cucumber' -$KCODE='u' unless Cucumber::RUBY_1_9 +$KCODE='u' if Cucumber::RUBY_1_8_7 RSpec.configure do |c| c.before do |
该提问来源于开源项目:cucumber/cucumber-ruby
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.