xing-root 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,163 @@
1
+ require 'fileutils'
2
+
3
+ module FileSandbox
4
+ def self.included(spec)
5
+ return unless spec.respond_to? :before
6
+
7
+ spec.before do
8
+ setup_sandbox
9
+ end
10
+
11
+ spec.after do
12
+ teardown_sandbox
13
+ end
14
+ end
15
+
16
+ class HaveContents
17
+ def initialize(contents)
18
+ @contents = contents
19
+ end
20
+
21
+ def matches?(target)
22
+ case @contents
23
+ when Regexp
24
+ @contents =~ target.contents
25
+ when String
26
+ @contents == target.contents
27
+ end
28
+ end
29
+ end
30
+
31
+ def have_contents(expected)
32
+ HaveContents.new(expected)
33
+ end
34
+
35
+ attr_reader :sandbox
36
+
37
+ def in_sandbox(&block)
38
+ raise "I expected to create a sandbox as you passed in a block to me" if !block_given?
39
+
40
+ setup_sandbox
41
+ original_error = nil
42
+
43
+ begin
44
+ yield @sandbox
45
+ rescue => e
46
+ original_error = e
47
+ raise
48
+ ensure
49
+ begin
50
+ teardown_sandbox
51
+ rescue
52
+ if original_error
53
+ STDERR.puts "ALERT: a test raised an error and failed to release some lock(s) in the sandbox directory"
54
+ raise(original_error)
55
+ else
56
+ raise
57
+ end
58
+ end
59
+ end
60
+ end
61
+
62
+ def setup_sandbox(path = '__sandbox')
63
+ unless @sandbox
64
+ @sandbox = Sandbox.new(path)
65
+ @__old_path_for_sandbox = Dir.pwd
66
+ Dir.chdir(@sandbox.root)
67
+ end
68
+ end
69
+
70
+ def teardown_sandbox
71
+ if @sandbox
72
+ Dir.chdir(@__old_path_for_sandbox)
73
+ @sandbox.clean_up
74
+ @sandbox = nil
75
+ end
76
+ end
77
+
78
+ class Sandbox
79
+ attr_reader :root
80
+
81
+ def initialize(path = '__sandbox')
82
+ @root = File.expand_path(path)
83
+ clean_up
84
+ FileUtils.mkdir_p @root
85
+ end
86
+
87
+ def [](name)
88
+ SandboxFile.new(File.join(@root, name), name)
89
+ end
90
+
91
+ # usage new :file=>'my file.rb', :with_contents=>'some stuff'
92
+ def new(options)
93
+ if options.has_key? :directory
94
+ dir = self[options.delete(:directory)]
95
+ FileUtils.mkdir_p dir.path
96
+ else
97
+ file = self[options.delete(:file)]
98
+ if (binary_content = options.delete(:with_binary_content) || options.delete(:with_binary_contents))
99
+ file.binary_content = binary_content
100
+ else
101
+ file.content = (options.delete(:with_content) || options.delete(:with_contents) || '')
102
+ end
103
+ end
104
+
105
+ raise "unexpected keys '#{options.keys.join(', ')}'" unless options.empty?
106
+
107
+ dir || file
108
+ end
109
+
110
+ def remove(options)
111
+ name = File.join(@root, options[:file])
112
+ FileUtils.remove_file name
113
+ end
114
+
115
+ def clean_up
116
+ FileUtils.rm_rf @root
117
+ if File.exists? @root
118
+ raise "Could not remove directory #{@root.inspect}, something is probably still holding a lock on it"
119
+ end
120
+ end
121
+ end
122
+
123
+
124
+ class SandboxFile
125
+ attr_reader :path
126
+
127
+ def initialize(path, sandbox_path)
128
+ @path = path
129
+ @sandbox_path = sandbox_path
130
+ end
131
+
132
+ def inspect
133
+ "SandboxFile: #@sandbox_path"
134
+ end
135
+
136
+ def exist?
137
+ File.exist? path
138
+ end
139
+
140
+ def content
141
+ File.read path
142
+ end
143
+
144
+ def content=(content)
145
+ FileUtils.mkdir_p File.dirname(@path)
146
+ File.open(@path, "w") {|f| f << content}
147
+ end
148
+
149
+ def binary_content=(content)
150
+ FileUtils.mkdir_p File.dirname(@path)
151
+ File.open(@path, "wb") {|f| f << content}
152
+ end
153
+
154
+ def create
155
+ self.content = ''
156
+ end
157
+
158
+ alias exists? exist?
159
+ alias contents content
160
+ alias contents= content=
161
+ alias binary_contents= binary_content=
162
+ end
163
+ end
@@ -0,0 +1,46 @@
1
+ require 'xing/tasks'
2
+
3
+
4
+ describe Xing::Tasks::Develop do
5
+ before :each do
6
+ Rake.application = nil
7
+ Xing::Tasks::Develop.new
8
+ end
9
+
10
+ it "creates all the develop rake tasks" do
11
+ expect(Rake.application.lookup "develop:launch_browser").to be_a(Rake::Task)
12
+ expect(Rake.application.lookup "develop:grunt_watch").to be_a(Rake::Task)
13
+ expect(Rake.application.lookup "develop:compass_watch").to be_a(Rake::Task)
14
+ expect(Rake.application.lookup "develop:rails_server").to be_a(Rake::Task)
15
+ expect(Rake.application.lookup "develop:sidekiq").to be_a(Rake::Task)
16
+ expect(Rake.application.lookup "develop:static_assets").to be_a(Rake::Task)
17
+ expect(Rake.application.lookup "develop:service:grunt_watch").to be_a(Rake::Task)
18
+ expect(Rake.application.lookup "develop:service:compass_watch").to be_a(Rake::Task)
19
+ expect(Rake.application.lookup "develop:service:rails_server").to be_a(Rake::Task)
20
+ expect(Rake.application.lookup "develop:service:sidekiq").to be_a(Rake::Task)
21
+ expect(Rake.application.lookup "develop:service:static_assets").to be_a(Rake::Task)
22
+ expect(Rake.application.lookup "develop:wait").to be_a(Rake::Task)
23
+ expect(Rake.application.lookup "develop:startup").to be_a(Rake::Task)
24
+ expect(Rake.application.lookup "develop:all").to be_a(Rake::Task)
25
+ end
26
+
27
+ it "doesn't create TMUX clones" do
28
+ manager = Rake.application.lookup("develop:grunt_watch").edict.manager
29
+ expect(Rake.application.lookup("develop:compass_watch").edict.manager).to eql(manager)
30
+ expect(Rake.application.lookup("develop:rails_server").edict.manager).to eql(manager)
31
+ expect(Rake.application.lookup("develop:sidekiq").edict.manager).to eql(manager)
32
+ expect(Rake.application.lookup("develop:static_assets").edict.manager).to eql(manager)
33
+ end
34
+
35
+ it "creates correct child tasks" do
36
+ expect(Rake.application.lookup("develop:grunt_watch").edict.child_task).to eq('develop:service:grunt_watch')
37
+ expect(Rake.application.lookup("develop:compass_watch").edict.child_task).to eq('develop:service:compass_watch')
38
+ expect(Rake.application.lookup("develop:rails_server").edict.child_task).to eq('develop:service:rails_server')
39
+ expect(Rake.application.lookup("develop:sidekiq").edict.child_task).to eq('develop:service:sidekiq')
40
+ expect(Rake.application.lookup("develop:static_assets").edict.child_task).to eq('develop:service:static_assets')
41
+ end
42
+
43
+ after :each do
44
+ Rake.application = nil
45
+ end
46
+ end
@@ -0,0 +1,26 @@
1
+ require 'xing/tasks/frontend'
2
+
3
+
4
+ describe Xing::Tasks::Frontend do
5
+ before :each do
6
+ Rake.application = nil
7
+ Xing::Tasks::Frontend.new do |fe|
8
+ fe.dir = "test-dir"
9
+ end
10
+ end
11
+
12
+ it "creates all the frontend rake tasks" do
13
+ expect(Rake.application.lookup "frontend:npm_install").to be_a(Rake::Task)
14
+ expect(Rake.application.lookup "frontend:bundle_install").to be_a(Rake::Task)
15
+ expect(Rake.application.lookup "frontend:check_dependencies").to be_a(Rake::Task)
16
+ expect(Rake.application.lookup "frontend:setup").to be_a(Rake::Task)
17
+ expect(Rake.application.lookup "frontend:code_structure").to be_a(Rake::Task)
18
+ expect(Rake.application.lookup "frontend:code_structure:app").to be_a(Rake::Task)
19
+ expect(Rake.application.lookup "frontend:code_structure:common").to be_a(Rake::Task)
20
+ expect(Rake.application.lookup "frontend:code_structure:framework").to be_a(Rake::Task)
21
+ end
22
+
23
+ after :each do
24
+ Rake.application = nil
25
+ end
26
+ end
@@ -0,0 +1,41 @@
1
+ require 'xing/edicts/structure-checker'
2
+ require 'support/file-sandbox'
3
+ require 'stringio'
4
+
5
+ describe Xing::Edicts::StructureChecker do
6
+ include FileSandbox
7
+
8
+ subject :checker do
9
+ Xing::Edicts::StructureChecker.new do |checker|
10
+ checker.dir = "test-dir"
11
+ checker.out_stream = stdout
12
+ end
13
+ end
14
+
15
+ let :stdout do
16
+ StringIO.new
17
+ end
18
+
19
+ describe "with a problem file" do
20
+ before :each do
21
+ @sandbox.new :file => "test-dir/problem.js", :with_content => "import Thing from '../../../somewhere/bad.js';"
22
+ end
23
+
24
+ it "should report errors" do
25
+ expect{subject.action}.to raise_error(Xing::Edicts::StructureChecker::Error)
26
+ expect(stdout.string).to match(%r{In test-dir/problem.js})
27
+ expect(stdout.string).to match(%r{'from' includes ../})
28
+ end
29
+ end
30
+
31
+ describe "with a good file" do
32
+ before :each do
33
+ @sandbox.new :file => "test-dir/problem.js", :with_content => "import Thing from 'somewhere/okay.js';"
34
+ end
35
+
36
+ it "should not report errors" do
37
+ expect{subject.action}.not_to raise_error
38
+ end
39
+ end
40
+
41
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: xing-root
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Judson Lester
8
+ - Patricia Ho
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-10-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: edict
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">"
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">"
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: caliph
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">"
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">"
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: mattock
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">"
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">"
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ description: |2
57
+ The root of all that is Xing in the world.
58
+ email:
59
+ - judson@lrdesign.com
60
+ - patricia@lrdesign.com
61
+ executables: []
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - lib/xing-root.rb
66
+ - lib/xing/edicts.rb
67
+ - lib/xing/edicts/clean-rake.rb
68
+ - lib/xing/edicts/clean-run.rb
69
+ - lib/xing/edicts/launch-browser.rb
70
+ - lib/xing/edicts/start-child.rb
71
+ - lib/xing/edicts/structure-checker.rb
72
+ - lib/xing/managers/child.rb
73
+ - lib/xing/managers/tmux.rb
74
+ - lib/xing/tasks.rb
75
+ - lib/xing/tasks/backend.rb
76
+ - lib/xing/tasks/build.rb
77
+ - lib/xing/tasks/develop.rb
78
+ - lib/xing/tasks/frontend.rb
79
+ - lib/xing/tasks/spec.rb
80
+ - lib/xing/tasks/tasklib.rb
81
+ - spec/edicts/clean_rake_spec.rb
82
+ - spec/edicts/clean_run_spec.rb
83
+ - spec/edicts/launch-browser_spec.rb
84
+ - spec/edicts/start-child_spec.rb
85
+ - spec/managers/tmux_spec.rb
86
+ - spec/support/file-sandbox.rb
87
+ - spec/tasks/develop_spec.rb
88
+ - spec/tasks/frontend_spec.rb
89
+ - spec/tasks/structure_checker_spec.rb
90
+ homepage: ''
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options:
96
+ - "--inline-source"
97
+ - "--main"
98
+ - doc/README
99
+ - "--title"
100
+ - xing-root-0.0.1 Documentation
101
+ require_paths:
102
+ - lib/
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project: xing-root
115
+ rubygems_version: 2.2.2
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: The Root of all Xing
119
+ test_files: []