embarista 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+
3
+ describe Embarista::Filters::RewriteMinispadeRequiresFilter do
4
+ MemoryFileWrapper = Rake::Pipeline::SpecHelpers::MemoryFileWrapper
5
+
6
+ let(:file_wrapper_class) { MemoryFileWrapper }
7
+
8
+ let(:input_js) {
9
+ <<-JS
10
+ require('baz');
11
+ require('../baz');
12
+ require('./baz');
13
+ require('./bar/baz');
14
+ JS
15
+ }
16
+
17
+ let(:input_files) {
18
+ [
19
+ MemoryFileWrapper.new("/path/to/input", "foo/bar.js", "UTF-8", input_js)
20
+ ]
21
+ }
22
+
23
+ let(:output_root) { '/path/to/output' }
24
+
25
+ let(:options) {
26
+ nil
27
+ }
28
+
29
+ let(:rake_application) {
30
+ Rake::Application.new
31
+ }
32
+
33
+ let(:subject) {
34
+ filter = described_class.new(options)
35
+ filter.file_wrapper_class = file_wrapper_class
36
+ filter.input_files = input_files
37
+ filter.output_root = output_root
38
+ filter.rake_application = rake_application
39
+ filter
40
+ }
41
+
42
+ it "rewrites require to be relative to input" do
43
+ tasks = subject.generate_rake_tasks
44
+ tasks.each(&:invoke)
45
+
46
+ file = MemoryFileWrapper.files["/path/to/output/foo/bar.js"]
47
+ file.body.should eq(<<-JS)
48
+ minispade.require('baz');
49
+ minispade.require('baz');
50
+ minispade.require('foo/baz');
51
+ minispade.require('foo/bar/baz');
52
+ JS
53
+ file.encoding.should eq('UTF-8')
54
+ end
55
+ end
@@ -0,0 +1,45 @@
1
+ require 'pry'
2
+ require 'embarista'
3
+
4
+ class Rake::Pipeline
5
+ module SpecHelpers
6
+
7
+ class MemoryFileWrapper < Struct.new(:root, :path, :encoding, :body)
8
+ @@files = {}
9
+ @@data = {}
10
+
11
+ def self.files
12
+ @@files
13
+ end
14
+
15
+ def self.data
16
+ @@data
17
+ end
18
+
19
+ def with_encoding(new_encoding)
20
+ self.class.new(root, path, new_encoding, body)
21
+ end
22
+
23
+ def fullpath
24
+ File.join(root, path)
25
+ end
26
+
27
+ def create
28
+ @@files[fullpath] = self
29
+ self.body = ""
30
+ yield
31
+ end
32
+
33
+ def read
34
+ body || @@data[fullpath] || ""
35
+ end
36
+
37
+ def write(contents)
38
+ self.body << contents
39
+ end
40
+ end
41
+ end
42
+ end
43
+
44
+ RSpec.configure do |config|
45
+ end
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+
3
+ describe Embarista::Filters::StripEmberAssertsFilter do
4
+ MemoryFileWrapper = Rake::Pipeline::SpecHelpers::MemoryFileWrapper
5
+
6
+ let(:file_wrapper_class) { MemoryFileWrapper }
7
+
8
+ let(:input_js) {
9
+ <<-JS
10
+ function foo() {
11
+ Ember.warn('do not foo');
12
+ Ember.assert('assert something', Ember.something);
13
+ Ember.deprecate('foo is deprecated');
14
+ Ember.deprecateFunc('foo is deprecated', Ember.foo);
15
+ }
16
+ JS
17
+ }
18
+
19
+ let(:input_files) {
20
+ [
21
+ MemoryFileWrapper.new("/path/to/input", "foo/bar.js", "UTF-8", input_js)
22
+ ]
23
+ }
24
+
25
+ let(:output_root) { '/path/to/output' }
26
+
27
+ let(:rake_application) {
28
+ Rake::Application.new
29
+ }
30
+
31
+ let(:subject) {
32
+ filter = described_class.new
33
+ filter.file_wrapper_class = file_wrapper_class
34
+ filter.input_files = input_files
35
+ filter.output_root = output_root
36
+ filter.rake_application = rake_application
37
+ filter
38
+ }
39
+
40
+ it "should strip Ember asserts, warnings and deprecations" do
41
+ tasks = subject.generate_rake_tasks
42
+ tasks.each(&:invoke)
43
+
44
+ file = MemoryFileWrapper.files["/path/to/output/foo/bar.js"]
45
+ file.body.should eq(<<-JS)
46
+ function foo() {
47
+
48
+
49
+
50
+
51
+ }
52
+ JS
53
+ file.encoding.should eq('UTF-8')
54
+ end
55
+ end