Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

FUCK YOU TOO RUBY!

  • Loading branch information...
commit 9ba900468a5e29e08eff0af8b70374a781b8bad4 1 parent 9e31a5f
@Manfred Manfred authored
View
6 Rakefile
@@ -14,3 +14,9 @@ task :examples do
sh "ruby -I examples -I lib #{example} -e ''"
end
end
+
+desc "Add magic encoding to all source files in the project"
+task :magic do
+ require File.expand_path('../rake/magic_encoding', __FILE__)
+ MagicEncoding.apply
+end
View
2  examples/001_basic_spec.rb
@@ -1,3 +1,5 @@
+# encoding: utf-8
+
require 'preamble'
describe "The test framework" do
View
2  examples/002_with_failure_spec.rb
@@ -1,3 +1,5 @@
+# encoding: utf-8
+
require 'preamble'
describe "The test framework" do
View
2  examples/003_framework_hook_spec.rb
@@ -1,3 +1,5 @@
+# encoding: utf-8
+
require 'preamble'
Peck::Context.once do |context|
View
2  examples/004_before_and_after_spec.rb
@@ -1,3 +1,5 @@
+# encoding: utf-8
+
require 'preamble'
class State
View
2  examples/005_concurrent_spec.rb
@@ -1,3 +1,5 @@
+# encoding: utf-8
+
require 'preamble'
Peck.concurrency = 100
View
2  examples/006_should_in_context_spec.rb
@@ -1,3 +1,5 @@
+# encoding: utf-8
+
require 'preamble'
class Peck
View
2  examples/assert.rb
@@ -1,3 +1,5 @@
+# encoding: utf-8
+
module Kernel
private
View
2  examples/preamble.rb
@@ -1,3 +1,5 @@
+# encoding: utf-8
+
require 'peck'
require 'peck/delegates'
require 'peck/counter'
View
2  lib/peck.rb
@@ -1,3 +1,5 @@
+# encoding: utf-8
+
class Peck
VERSION = "0.1.0"
View
2  lib/peck/context.rb
@@ -1,3 +1,5 @@
+# encoding: utf-8
+
class Peck
class Context
attr_reader :specification
View
2  lib/peck/counter.rb
@@ -1,3 +1,5 @@
+# encoding: utf-8
+
class Peck
class << self
attr_accessor :counter
View
2  lib/peck/debug.rb
@@ -1,3 +1,5 @@
+# encoding: utf-8
+
class Peck
def self.logger
@logger ||= begin
View
2  lib/peck/delegates.rb
@@ -1,3 +1,5 @@
+# encoding: utf-8
+
require 'set'
class Peck
View
2  lib/peck/error.rb
@@ -1,3 +1,5 @@
+# encoding: utf-8
+
class Peck
class Error < RuntimeError
attr_accessor :type
View
2  lib/peck/expectations.rb
@@ -1,3 +1,5 @@
+# encoding: utf-8
+
require 'peck/error'
class Peck
View
2  lib/peck/flavors/quiet.rb
@@ -1,3 +1,5 @@
+# encoding: utf-8
+
require 'peck'
require 'peck/delegates'
require 'peck/counter'
View
2  lib/peck/flavors/vanilla.rb
@@ -1,3 +1,5 @@
+# encoding: utf-8
+
require 'peck'
require 'peck/delegates'
require 'peck/counter'
View
2  lib/peck/notifiers/base.rb
@@ -1,3 +1,5 @@
+# encoding: utf-8
+
class Peck
class Notifiers
class Base
View
2  lib/peck/notifiers/default.rb
@@ -1,3 +1,5 @@
+# encoding: utf-8
+
require 'peck/notifiers/base'
class Peck
View
2  lib/peck/specification.rb
@@ -1,3 +1,5 @@
+# encoding: utf-8
+
class Peck
class Context
def self.it(description, &block)
View
51 rake/magic_encoding.rb
@@ -0,0 +1,51 @@
+# encoding: utf-8
+
+require 'find'
+
+class MagicEncoding
+ MAGIC_ENCODING = "# encoding: utf-8\n\n"
+ SOURCE_FILE_RE = /\.(rb|rake)$/
+
+ def self.root
+ File.expand_path('../../', __FILE__)
+ end
+
+ def self.fix(content)
+ MAGIC_ENCODING + content.lstrip
+ end
+
+ def self.change?(filename)
+ File.open(filename) do |file|
+ if file.read(10) != '# encoding'
+ file.seek(0)
+ file.read
+ end
+ end
+ end
+
+ def self.files(count)
+ "#{count} #{count == 1 ? 'file' : 'files'}"
+ end
+
+ def self.apply
+ ignored = 0
+ fixed = 0
+
+ Find.find(root) do |filename|
+ if File.file?(filename)
+ if filename =~ SOURCE_FILE_RE
+ if content = change?(filename)
+ File.open(filename, 'w') do |file|
+ file.write(fix(content))
+ end
+ fixed += 1
+ else
+ ignored += 1
+ end
+ end
+ end
+ end
+
+ puts "Fixed #{files(fixed)}, #{files(ignored)} were already fine."
+ end
+end
View
2  spec/context_spec.rb
@@ -1,3 +1,5 @@
+# encoding: utf-8
+
require File.expand_path('../preamble', __FILE__)
describe "The context" do
View
2  spec/default_notifier_spec.rb
@@ -1,3 +1,5 @@
+# encoding: utf-8
+
require File.expand_path('../preamble', __FILE__)
require 'stringio'
View
2  spec/delegates_spec.rb
@@ -1,3 +1,5 @@
+# encoding: utf-8
+
require File.expand_path('../preamble', __FILE__)
class Bird
View
2  spec/exit_code_spec.rb
@@ -1,3 +1,5 @@
+# encoding: utf-8
+
require File.expand_path('../preamble', __FILE__)
describe Peck do
View
2  spec/preamble.rb
@@ -1,3 +1,5 @@
+# encoding: utf-8
+
$:.unshift File.expand_path("../../lib", __FILE__)
require 'peck/flavors/vanilla'

5 comments on commit 9ba9004

@floere

LOL

@zenspider

OMG I love this so much

@floere

I'm wondering: What would the perfect solution look like? (If we had it in Ruby)

@Manfred
Owner

@floere: The solution is in Ruby 2.0, it treats Ruby source files as UTF-8 by default.

@floere

@Manfred Fair enough.

Please sign in to comment.
Something went wrong with that request. Please try again.