motion-bundler 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.rdoc +11 -0
- data/VERSION +1 -1
- data/bin/motion-bundler +10 -0
- data/lib/motion-bundler.rb +34 -34
- data/lib/motion-bundler/cli.rb +31 -0
- data/lib/motion-bundler/config.rb +12 -0
- data/lib/motion-bundler/require/resolve.rb +6 -4
- data/lib/motion-bundler/require/ripper.rb +4 -3
- data/lib/motion-bundler/require/tracer/hooks.rb +1 -8
- data/lib/motion-bundler/require/tracer/log.rb +24 -10
- data/lib/motion-bundler/simulator/console.rb +1 -1
- data/lib/motion-bundler/version.rb +1 -1
- data/motion-bundler.gemspec +1 -0
- data/sample_app/Rakefile +7 -0
- data/sample_app/app/app_delegate.rb +4 -0
- data/sample_app/app/controllers/app_controller.rb +55 -0
- data/sample_app/mocks/{socket.rb → socket.so.rb} +0 -0
- data/test/.gemfiles/simulator/test_setup.lock +3 -1
- data/test/lib/e.rb +0 -0
- data/test/unit/require/test_resolve.rb +6 -0
- data/test/unit/require/test_ripper.rb +5 -5
- data/test/unit/require/tracer/test_log.rb +36 -1
- data/test/unit/simulator/test_console.rb +3 -3
- data/test/unit/test_config.rb +12 -1
- data/test/unit/test_motion-bundler.rb +8 -4
- metadata +23 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a511acdb21993390c91f8d8663bdd3c73e76a656
|
4
|
+
data.tar.gz: f66639236864827139db740e12941518992da621
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 676d574227184e574f1203e65ad6934cd34d3357af328d46e18a25356f77e6c1baf986784c9467a158bdba22b0dcd324def4b147d19c63b651387ef4ba0b157c
|
7
|
+
data.tar.gz: d82d00aa08d67cb13b5913980796fe67800d72b4bf2be3c671dbb414a9548f03021f51efa9a790f227585587ea0e9c9909de8027d84054e8ec2ae30ed59a1feb
|
data/CHANGELOG.rdoc
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
= MotionBundler CHANGELOG
|
2
2
|
|
3
|
+
== Version 0.1.7 (June 19, 2013)
|
4
|
+
|
5
|
+
* Added MotionBundler::CLI which outputs files, files dependencies and requires as YAML (usage: `bundle exec motion-bundler trace cgi`)
|
6
|
+
* Only resolving paths within $LOAD_PATH and gems paths when explicitly requested (only resolving mocks at default)
|
7
|
+
* Being able to pass a "scope path" to Ripper.new which determines whether to immediately "rip" an analyzed Ruby source file
|
8
|
+
* Being able to trace files which are already required (thanks Geoff Ereth for issuing)
|
9
|
+
* Not rescuing LoadError when hooking into the `require` method
|
10
|
+
* Renamed REQUIRED to REQUIRES
|
11
|
+
* Corrected merging ripper with tracer files dependencies
|
12
|
+
* Introduced app.register in case of correcting missing require statements e.g. in REXML (thanks Jeff Enderwick @jeff7091 for issuing)
|
13
|
+
|
3
14
|
== Version 0.1.6 (June 14, 2013)
|
4
15
|
|
5
16
|
* Removed optional `strict` argument within Require.resolve
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.7
|
data/bin/motion-bundler
ADDED
data/lib/motion-bundler.rb
CHANGED
@@ -18,15 +18,15 @@ module MotionBundler
|
|
18
18
|
Motion::Project::App.setup do |app|
|
19
19
|
touch_motion_bundler
|
20
20
|
|
21
|
-
files, files_dependencies,
|
22
|
-
ripper_require files, files_dependencies,
|
23
|
-
tracer_require files, files_dependencies,
|
21
|
+
files, files_dependencies, requires = app.files, {}, []
|
22
|
+
ripper_require files, files_dependencies, requires
|
23
|
+
tracer_require files, files_dependencies, requires, &block
|
24
24
|
|
25
25
|
normalize! files
|
26
26
|
normalize! files_dependencies
|
27
|
-
|
27
|
+
requires.sort!.uniq!
|
28
28
|
|
29
|
-
write_motion_bundler files, files_dependencies,
|
29
|
+
write_motion_bundler files, files_dependencies, requires
|
30
30
|
|
31
31
|
app.files = files
|
32
32
|
app.files_dependencies files_dependencies
|
@@ -59,54 +59,54 @@ private
|
|
59
59
|
File.open(MOTION_BUNDLER_FILE, "w") {}
|
60
60
|
end
|
61
61
|
|
62
|
-
def ripper_require(files, files_dependencies,
|
63
|
-
ripper = Require::Ripper.new
|
62
|
+
def ripper_require(files, files_dependencies, requires)
|
63
|
+
ripper = Require::Ripper.new Dir["app/**/*.rb"].collect{|x| "./#{x}"}
|
64
64
|
|
65
65
|
files.replace(
|
66
66
|
ripper.files + files
|
67
67
|
)
|
68
|
-
files_dependencies.
|
69
|
-
|
70
|
-
)
|
71
|
-
required.concat(
|
68
|
+
ripper.files_dependencies.each{|file, paths| (files_dependencies[file] ||= []).concat paths}
|
69
|
+
requires.concat(
|
72
70
|
ripper.requires.values.flatten
|
73
71
|
)
|
74
72
|
end
|
75
73
|
|
76
|
-
def tracer_require(files, files_dependencies,
|
74
|
+
def tracer_require(files, files_dependencies, requires)
|
75
|
+
config = Config.new
|
76
|
+
if block_given?
|
77
|
+
yield config
|
78
|
+
end
|
79
|
+
|
77
80
|
Require.mock_and_trace do
|
78
81
|
require MOTION_BUNDLER_FILE
|
79
82
|
require boot_file
|
80
83
|
Bundler.require :motion
|
81
|
-
app_requires.
|
82
|
-
|
83
|
-
true
|
84
|
-
end
|
85
|
-
if block_given?
|
86
|
-
config = Config.new
|
87
|
-
yield config
|
88
|
-
config.requires.each{|file| require file, "APP"}
|
89
|
-
end
|
84
|
+
app_requires.each{|file| require file, "APP"}
|
85
|
+
config.requires.each{|file| require file, "APP"}
|
90
86
|
end
|
91
87
|
|
92
88
|
files.replace(
|
93
|
-
Require.files + files - ["APP", "BUNDLER", __FILE__]
|
89
|
+
Require.files + config.files + files - ["APP", "BUNDLER", __FILE__]
|
94
90
|
)
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
end
|
100
|
-
dependencies.delete("APP")
|
101
|
-
dependencies.delete(__FILE__)
|
91
|
+
|
92
|
+
Require.files_dependencies.tap do |dependencies|
|
93
|
+
(dependencies.delete("BUNDLER") || []).each do |file|
|
94
|
+
(dependencies[file] ||= []).unshift boot_file
|
102
95
|
end
|
103
|
-
|
104
|
-
|
105
|
-
|
96
|
+
dependencies.delete("APP")
|
97
|
+
dependencies.delete(__FILE__)
|
98
|
+
end.each do |file, paths|
|
99
|
+
(files_dependencies[file] ||= []).concat paths
|
100
|
+
end
|
101
|
+
|
102
|
+
config.files_dependencies.each{|file, paths| (files_dependencies[file] ||= []).concat paths}
|
103
|
+
|
104
|
+
requires.concat(
|
105
|
+
Require.requires.values.flatten + config.requires
|
106
106
|
)
|
107
107
|
end
|
108
108
|
|
109
|
-
def write_motion_bundler(files, files_dependencies,
|
109
|
+
def write_motion_bundler(files, files_dependencies, requires)
|
110
110
|
File.open(MOTION_BUNDLER_FILE, "w") do |file|
|
111
111
|
files_dependencies = files_dependencies.dup.tap do |dependencies|
|
112
112
|
if motion_bundler_dependencies = dependencies.delete(__FILE__)
|
@@ -117,7 +117,7 @@ private
|
|
117
117
|
module MotionBundler
|
118
118
|
FILES = #{pretty_inspect files, 2}
|
119
119
|
FILES_DEPENDENCIES = #{pretty_inspect files_dependencies, 2}
|
120
|
-
|
120
|
+
REQUIRES = #{pretty_inspect requires, 2}
|
121
121
|
end
|
122
122
|
RUBY_CODE
|
123
123
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "yaml"
|
2
|
+
require "thor"
|
3
|
+
require "motion-bundler"
|
4
|
+
|
5
|
+
$CLI = true
|
6
|
+
|
7
|
+
module MotionBundler
|
8
|
+
class CLI < Thor
|
9
|
+
|
10
|
+
default_task :trace
|
11
|
+
|
12
|
+
desc "trace [FILE]", "Trace files and their mutual dependencies when requiring [FILE]"
|
13
|
+
def trace(file)
|
14
|
+
Require.mock_and_trace do
|
15
|
+
require file, "APP"
|
16
|
+
end
|
17
|
+
puts YAML.dump({
|
18
|
+
"FILES" => Require.files,
|
19
|
+
"FILES_DEPENDENCIES" => Require.files_dependencies,
|
20
|
+
"REQUIRES" => Require.requires
|
21
|
+
})
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def method_missing(method, *args)
|
27
|
+
raise Error, "Unrecognized command \"#{method}\". Please consult `motion-bundler help`."
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -2,10 +2,22 @@ module MotionBundler
|
|
2
2
|
class Config
|
3
3
|
def initialize
|
4
4
|
@requires = []
|
5
|
+
@files_dependencies = {}
|
5
6
|
end
|
6
7
|
def require(name)
|
7
8
|
@requires << name
|
8
9
|
end
|
10
|
+
def register(files_dependencies)
|
11
|
+
files_dependencies.each do |file, paths|
|
12
|
+
(@files_dependencies[Require.resolve(file, false)] ||= []).concat paths.collect{|file| Require.resolve(file, false)}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
def files
|
16
|
+
(@files_dependencies.keys + @files_dependencies.values).flatten.uniq
|
17
|
+
end
|
18
|
+
def files_dependencies
|
19
|
+
@files_dependencies.dup
|
20
|
+
end
|
9
21
|
def requires
|
10
22
|
@requires.dup
|
11
23
|
end
|
@@ -2,10 +2,10 @@ module MotionBundler
|
|
2
2
|
module Require
|
3
3
|
module Resolve
|
4
4
|
|
5
|
-
def resolve(path)
|
5
|
+
def resolve(path, only_mocks = true)
|
6
6
|
base_path = path.gsub(/\.rb$/, "")
|
7
7
|
|
8
|
-
load_paths.each do |load_path|
|
8
|
+
load_paths(only_mocks).each do |load_path|
|
9
9
|
if (file = Dir["#{load_path}/#{base_path}.rb"].first)
|
10
10
|
return file
|
11
11
|
end
|
@@ -16,8 +16,10 @@ module MotionBundler
|
|
16
16
|
|
17
17
|
private
|
18
18
|
|
19
|
-
def load_paths
|
20
|
-
Mocker.dirs + Mocker.dirs.collect_concat{|x| Dir["#{x}/*"]}
|
19
|
+
def load_paths(only_mocks)
|
20
|
+
(Mocker.dirs + Mocker.dirs.collect_concat{|x| Dir["#{x}/*"]}).tap do |load_paths|
|
21
|
+
load_paths.concat($LOAD_PATH + gem_paths) unless only_mocks
|
22
|
+
end
|
21
23
|
end
|
22
24
|
|
23
25
|
class GemPath
|
@@ -5,8 +5,9 @@ module MotionBundler
|
|
5
5
|
module Require
|
6
6
|
class Ripper
|
7
7
|
|
8
|
-
def initialize(
|
8
|
+
def initialize(sources, scope = MotionBundler::PROJECT_PATH)
|
9
9
|
@sources = sources
|
10
|
+
@scope = scope
|
10
11
|
@files = Set.new
|
11
12
|
@files_dependencies = {}
|
12
13
|
@requires = {}
|
@@ -41,7 +42,7 @@ module MotionBundler
|
|
41
42
|
if method == :require_relative
|
42
43
|
File.expand_path("../#{file}.rb", source)
|
43
44
|
else
|
44
|
-
Require.resolve(file)
|
45
|
+
Require.resolve(file, false)
|
45
46
|
end
|
46
47
|
end
|
47
48
|
|
@@ -52,7 +53,7 @@ module MotionBundler
|
|
52
53
|
expanded_path = File.expand_path(file)
|
53
54
|
|
54
55
|
unless @sources.any?{|x| File.expand_path(x) == expanded_path}
|
55
|
-
if expanded_path.
|
56
|
+
if expanded_path.match(/^#{@scope}/)
|
56
57
|
added_sources << file
|
57
58
|
else
|
58
59
|
MotionBundler.app_require file
|
@@ -30,14 +30,7 @@ module MotionBundler
|
|
30
30
|
def require_with_mb_trace(path, _caller = nil, _path = nil)
|
31
31
|
result = nil
|
32
32
|
MotionBundler::Require::Tracer.log.register(_caller || caller[0], _path || path) do
|
33
|
-
result =
|
34
|
-
require_without_mb_trace path
|
35
|
-
rescue LoadError => e
|
36
|
-
false
|
37
|
-
end
|
38
|
-
unless result
|
39
|
-
{:required => MotionBundler::Require.resolve(path)}
|
40
|
-
end
|
33
|
+
result = require_without_mb_trace path
|
41
34
|
end
|
42
35
|
result
|
43
36
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require "yaml"
|
2
|
+
|
1
3
|
module MotionBundler
|
2
4
|
module Require
|
3
5
|
module Tracer
|
@@ -28,7 +30,7 @@ module MotionBundler
|
|
28
30
|
end
|
29
31
|
|
30
32
|
def register(file, path)
|
31
|
-
return
|
33
|
+
return if !file.match(/^([A-Z]+)$/) && !file.match(/^(.*\.rb):(\d+)/)
|
32
34
|
|
33
35
|
file = $1.include?("/bundler/") ? "BUNDLER" : $1
|
34
36
|
line = $1.include?("/bundler/") ? nil : $2
|
@@ -37,25 +39,37 @@ module MotionBundler
|
|
37
39
|
dependencies = (@files_dependencies[file] ||= [])
|
38
40
|
index = dependencies.size
|
39
41
|
|
40
|
-
|
41
|
-
|
42
|
-
result[:required]
|
43
|
-
else
|
44
|
-
loaded_features.last
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
if loaded_feature
|
42
|
+
if yield
|
43
|
+
loaded_feature = loaded_features.last
|
49
44
|
@files << file unless @files.include? file
|
50
45
|
@files << loaded_feature
|
51
46
|
dependencies.insert index, loaded_feature
|
52
47
|
else
|
53
48
|
@files_dependencies.delete file if dependencies.empty?
|
49
|
+
if file.match(/^([A-Z]+)$/)
|
50
|
+
if $CLI
|
51
|
+
ripper = Require::Ripper.new [path], "/"
|
52
|
+
merge! ripper.files, ripper.files_dependencies, ripper.requires
|
53
|
+
else
|
54
|
+
tracer = YAML.load `motion-bundler trace #{path}`
|
55
|
+
merge! *tracer.values_at("FILES", "FILES_DEPENDENCIES", "REQUIRES")
|
56
|
+
end
|
57
|
+
end
|
54
58
|
end
|
55
59
|
|
56
60
|
true
|
57
61
|
end
|
58
62
|
|
63
|
+
def merge!(files, files_dependencies, requires)
|
64
|
+
@files.merge files
|
65
|
+
files_dependencies.each do |file, dependencies|
|
66
|
+
(@files_dependencies[file] ||= []).concat dependencies
|
67
|
+
end
|
68
|
+
requires.each do |file, paths|
|
69
|
+
(@requires[file] ||= []).concat paths
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
59
73
|
private
|
60
74
|
|
61
75
|
def loaded_features
|
@@ -5,7 +5,7 @@ module MotionBundler
|
|
5
5
|
class Warning
|
6
6
|
def print
|
7
7
|
if require_statement = [:require, :require_relative, :load, :autoload].include?(@method)
|
8
|
-
return if MotionBundler::
|
8
|
+
return if MotionBundler::REQUIRES.include? @args.last
|
9
9
|
end
|
10
10
|
|
11
11
|
warning = "Warning Called `#{[@object, @method].compact.join "."}"
|
data/motion-bundler.gemspec
CHANGED
data/sample_app/Rakefile
CHANGED
@@ -11,7 +11,14 @@ Motion::Project::App.setup do |app|
|
|
11
11
|
app.name = "MBundler"
|
12
12
|
end
|
13
13
|
|
14
|
+
require "/Users/paulengel/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/cgi/html.rb"
|
15
|
+
|
14
16
|
# Track and specify files and their mutual dependencies within the :motion Bundler group
|
15
17
|
MotionBundler.setup do |app|
|
16
18
|
app.require "base64"
|
19
|
+
app.register({
|
20
|
+
"rexml/xmldecl" => ["rexml/child"],
|
21
|
+
"rexml/doctype" => ["rexml/child"],
|
22
|
+
"rexml/parsers/baseparser" => ["set"]
|
23
|
+
})
|
17
24
|
end
|
@@ -3,6 +3,9 @@ require "strscan"
|
|
3
3
|
require "zlib"
|
4
4
|
require "httparty"
|
5
5
|
require "net/pop"
|
6
|
+
require "rexml/document"
|
7
|
+
require "socket"
|
8
|
+
|
6
9
|
require_relative "../../lib/foo"
|
7
10
|
|
8
11
|
class AppController < UIViewController
|
@@ -54,6 +57,58 @@ class AppController < UIViewController
|
|
54
57
|
p enc
|
55
58
|
p Base64.decode64(enc)
|
56
59
|
|
60
|
+
# Testing REXML::Document
|
61
|
+
|
62
|
+
xml = <<-XML
|
63
|
+
<inventory title="OmniCorp Store #45x10^3">
|
64
|
+
<section name="health">
|
65
|
+
<item upc="123456789" stock="12">
|
66
|
+
<name>Invisibility Cream</name>
|
67
|
+
<price>14.50</price>
|
68
|
+
<description>Makes you invisible</description>
|
69
|
+
</item>
|
70
|
+
<item upc="445322344" stock="18">
|
71
|
+
<name>Levitation Salve</name>
|
72
|
+
<price>23.99</price>
|
73
|
+
<description>Levitate yourself for up to 3 hours per application</description>
|
74
|
+
</item>
|
75
|
+
</section>
|
76
|
+
<section name="food">
|
77
|
+
<item upc="485672034" stock="653">
|
78
|
+
<name>Blork and Freen Instameal</name>
|
79
|
+
<price>4.95</price>
|
80
|
+
<description>A tasty meal in a tablet; just add water</description>
|
81
|
+
</item>
|
82
|
+
<item upc="132957764" stock="44">
|
83
|
+
<name>Grob winglets</name>
|
84
|
+
<price>3.56</price>
|
85
|
+
<description>Tender winglets of Grob. Just add water</description>
|
86
|
+
</item>
|
87
|
+
</section>
|
88
|
+
</inventory>
|
89
|
+
XML
|
90
|
+
|
91
|
+
doc = REXML::Document.new xml
|
92
|
+
root = doc.root
|
93
|
+
|
94
|
+
doc.elements.each("inventory/section"){|element| puts element.attributes["name"]}
|
95
|
+
# => health
|
96
|
+
# => food
|
97
|
+
doc.elements.each("*/section/item"){|element| puts element.attributes["upc"]}
|
98
|
+
# => 123456789
|
99
|
+
# => 445322344
|
100
|
+
# => 485672034
|
101
|
+
# => 132957764
|
102
|
+
|
103
|
+
puts root.attributes["title"]
|
104
|
+
# => OmniCorp Store #45x10^3
|
105
|
+
puts root.elements["section/item[@stock='44']"].attributes["upc"]
|
106
|
+
# => 132957764
|
107
|
+
puts root.elements["section"].attributes["name"]
|
108
|
+
# => health (returns the first encountered matching element)
|
109
|
+
puts root.elements[1].attributes["name"]
|
110
|
+
# => health (returns the FIRST child element)
|
111
|
+
|
57
112
|
# Say thanks
|
58
113
|
|
59
114
|
alert = UIAlertView.new
|
File without changes
|
@@ -1,7 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: /Users/paulengel/Sources/motion-bundler
|
3
3
|
specs:
|
4
|
-
motion-bundler (0.1.
|
4
|
+
motion-bundler (0.1.7)
|
5
|
+
thor
|
5
6
|
|
6
7
|
PATH
|
7
8
|
remote: /Users/paulengel/Sources/motion-bundler/test/gems/slot_machine
|
@@ -11,6 +12,7 @@ PATH
|
|
11
12
|
GEM
|
12
13
|
remote: https://rubygems.org/
|
13
14
|
specs:
|
15
|
+
thor (0.18.1)
|
14
16
|
|
15
17
|
PLATFORMS
|
16
18
|
ruby
|
data/test/lib/e.rb
ADDED
File without changes
|
@@ -22,6 +22,12 @@ module Unit
|
|
22
22
|
assert_equal "#{mocks_dir}/psych_foo-0.1.0/psych/handler.rb", Require.resolve("psych/handler")
|
23
23
|
assert_equal "#{mocks_dir}/psych_foo-0.1.0/psych/handler.rb", Require.resolve("psych/handler")
|
24
24
|
assert_equal "#{MotionBundler::Require::Mocker::GEM_MOCKS}/httparty.rb", Require.resolve("httparty")
|
25
|
+
|
26
|
+
require "cgi"
|
27
|
+
cgi = $LOADED_FEATURES.detect{|x| x.include? "/cgi.rb"}
|
28
|
+
|
29
|
+
assert_equal "cgi", Require.resolve("cgi")
|
30
|
+
assert_equal cgi, Require.resolve("cgi", false)
|
25
31
|
end
|
26
32
|
|
27
33
|
end
|
@@ -41,18 +41,18 @@ module Unit
|
|
41
41
|
lib_baz_builder.expects(:requires).returns []
|
42
42
|
MotionBundler::Require::Ripper::Builder.expects(:new).with("lib/baz.rb").returns lib_baz_builder
|
43
43
|
|
44
|
-
MotionBundler::Require.expects(:resolve).with("stringio").returns("/stdlib/stringio.rb")
|
45
|
-
MotionBundler::Require.expects(:resolve).with("strscan").returns("mocks/strscan.rb")
|
46
|
-
MotionBundler::Require.expects(:resolve).with("baz").returns("lib/baz.rb")
|
44
|
+
MotionBundler::Require.expects(:resolve).with("stringio", false).returns("/stdlib/stringio.rb")
|
45
|
+
MotionBundler::Require.expects(:resolve).with("strscan", false).returns("mocks/strscan.rb")
|
46
|
+
MotionBundler::Require.expects(:resolve).with("baz", false).returns("lib/baz.rb")
|
47
47
|
|
48
48
|
MotionBundler.expects(:app_require).with("/stdlib/stringio.rb")
|
49
49
|
|
50
|
-
ripper = MotionBundler::Require::Ripper.new(
|
50
|
+
ripper = MotionBundler::Require::Ripper.new([
|
51
51
|
"./app/controllers/app_controller.rb",
|
52
52
|
"./app/controllers/foo_controller.rb",
|
53
53
|
"./app/controllers/baz_controller.rb",
|
54
54
|
"./app/controllers/qux.rb"
|
55
|
-
)
|
55
|
+
])
|
56
56
|
|
57
57
|
assert_equal([
|
58
58
|
"./app/controllers/app_controller.rb",
|
@@ -39,7 +39,7 @@ module Unit
|
|
39
39
|
loaded_features << "file2"
|
40
40
|
end
|
41
41
|
@log.register "/Sources/lib/foo.rb:12", "qux" do
|
42
|
-
|
42
|
+
false
|
43
43
|
end
|
44
44
|
loaded_features << "file1"
|
45
45
|
end
|
@@ -79,6 +79,41 @@ module Unit
|
|
79
79
|
"/Sources/lib/foo.rb:12" => %w(qux)
|
80
80
|
}, @log.requires)
|
81
81
|
end
|
82
|
+
|
83
|
+
it "should be able to trace files that are already loaded" do
|
84
|
+
self.expects(:require_without_mb_trace).with("cgi").returns(false)
|
85
|
+
MotionBundler::Require::Tracer.log.expects(:merge!)
|
86
|
+
MotionBundler::Require.mock_and_trace do
|
87
|
+
require "cgi", "APP"
|
88
|
+
end
|
89
|
+
|
90
|
+
$CLI = true
|
91
|
+
self.expects(:require_without_mb_trace).with("cgi").returns(false)
|
92
|
+
File.expects(:read).with("cgi").returns("")
|
93
|
+
MotionBundler::Require::Tracer.log.expects(:merge!)
|
94
|
+
MotionBundler::Require.mock_and_trace do
|
95
|
+
require "cgi", "APP"
|
96
|
+
end
|
97
|
+
$CLI = false
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should be able to merge files, files dependencies and requires" do
|
101
|
+
@log.instance_variable_set :@files, Set.new(%w(a b))
|
102
|
+
@log.instance_variable_set :@files_dependencies, {"c" => %w(d e)}
|
103
|
+
@log.instance_variable_set :@requires, {"f" => %w(g)}
|
104
|
+
|
105
|
+
@log.merge! %w(h i), {"c" => %w(j), "k" => %w(l m)}, {"f" => %w(n), "o" => %w(p q)}
|
106
|
+
|
107
|
+
assert_equal(%w(a b h i), @log.files)
|
108
|
+
assert_equal({
|
109
|
+
"c" => %w(d e j),
|
110
|
+
"k" => %w(l m)
|
111
|
+
}, @log.files_dependencies)
|
112
|
+
assert_equal({
|
113
|
+
"f" => %w(g n),
|
114
|
+
"o" => %w(p q)
|
115
|
+
}, @log.requires)
|
116
|
+
end
|
82
117
|
end
|
83
118
|
|
84
119
|
end
|
@@ -7,12 +7,12 @@ module Unit
|
|
7
7
|
|
8
8
|
describe MotionBundler::Simulator::Console do
|
9
9
|
before do
|
10
|
-
MotionBundler.send :remove_const, :
|
11
|
-
MotionBundler::
|
10
|
+
MotionBundler.send :remove_const, :REQUIRES if defined?(MotionBundler::REQUIRES)
|
11
|
+
MotionBundler::REQUIRES = ["baz"]
|
12
12
|
end
|
13
13
|
|
14
14
|
after do
|
15
|
-
MotionBundler.send :remove_const, :
|
15
|
+
MotionBundler.send :remove_const, :REQUIRES
|
16
16
|
end
|
17
17
|
|
18
18
|
it "should print warnings as expected" do
|
data/test/unit/test_config.rb
CHANGED
@@ -11,8 +11,19 @@ module Unit
|
|
11
11
|
config.require "foo"
|
12
12
|
config.require "foo/baz"
|
13
13
|
assert_equal %w(foo foo/baz), config.requires
|
14
|
-
|
15
14
|
assert config.requires.object_id != config.requires.object_id
|
15
|
+
|
16
|
+
cgi = MotionBundler::Require.resolve "cgi", false
|
17
|
+
html = MotionBundler::Require.resolve "cgi/html", false
|
18
|
+
|
19
|
+
config.register({"cgi" => ["cgi/html"]})
|
20
|
+
assert_equal([cgi, html], config.files)
|
21
|
+
assert_equal({cgi => [html]}, config.files_dependencies)
|
22
|
+
|
23
|
+
cookie = MotionBundler::Require.resolve "cgi/cookie", false
|
24
|
+
|
25
|
+
config.instance_variable_get(:@files_dependencies)[cgi].expects(:concat).with([cookie])
|
26
|
+
config.register({"cgi" => ["cgi/cookie"]})
|
16
27
|
end
|
17
28
|
end
|
18
29
|
|
@@ -46,7 +46,7 @@ module Unit
|
|
46
46
|
"qux"
|
47
47
|
]
|
48
48
|
}
|
49
|
-
|
49
|
+
REQUIRES = [
|
50
50
|
"fu",
|
51
51
|
"baz"
|
52
52
|
]
|
@@ -65,13 +65,17 @@ module Unit
|
|
65
65
|
end
|
66
66
|
|
67
67
|
describe "calling `setup`" do
|
68
|
+
before do
|
69
|
+
MotionBundler.send(:app_requires).clear
|
70
|
+
end
|
71
|
+
|
68
72
|
it "should require the :motion Bundler group and mock and trace requires" do
|
69
73
|
object = mock "object"
|
70
74
|
object.expects :do_something
|
71
75
|
|
72
76
|
Bundler.expects(:require).with(:motion)
|
73
77
|
MotionBundler.setup do |app|
|
74
|
-
app.require "
|
78
|
+
app.require lib_file("e")
|
75
79
|
object.do_something
|
76
80
|
end
|
77
81
|
|
@@ -122,7 +126,7 @@ module Unit
|
|
122
126
|
]
|
123
127
|
})
|
124
128
|
|
125
|
-
Motion::Project::App.any_instance.expects(:files=).with(expand_paths
|
129
|
+
Motion::Project::App.any_instance.expects(:files=).with(expand_paths([
|
126
130
|
motion_bundler_file("motion-bundler/simulator/boot.rb"),
|
127
131
|
motion_bundler_file("motion-bundler/simulator/core_ext.rb"),
|
128
132
|
motion_bundler_file("motion-bundler/simulator/motion-bundler.rb"),
|
@@ -132,7 +136,7 @@ module Unit
|
|
132
136
|
"ruby/foo.rb",
|
133
137
|
"delegate.rb",
|
134
138
|
"controller.rb"
|
135
|
-
])
|
139
|
+
]))
|
136
140
|
|
137
141
|
Motion::Project::App.any_instance.expects(:files_dependencies).with(expand_paths({
|
138
142
|
motion_bundler_file("motion-bundler/simulator/boot.rb") => [
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: motion-bundler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Engel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-06-
|
11
|
+
date: 2013-06-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -52,10 +52,25 @@ dependencies:
|
|
52
52
|
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: thor
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
description: Use Ruby gems and mock require statements within RubyMotion applications
|
56
70
|
email:
|
57
71
|
- paul.engel@holder.nl
|
58
|
-
executables:
|
72
|
+
executables:
|
73
|
+
- motion-bundler
|
59
74
|
extensions: []
|
60
75
|
extra_rdoc_files: []
|
61
76
|
files:
|
@@ -67,7 +82,9 @@ files:
|
|
67
82
|
- README.md
|
68
83
|
- Rakefile
|
69
84
|
- VERSION
|
85
|
+
- bin/motion-bundler
|
70
86
|
- lib/motion-bundler.rb
|
87
|
+
- lib/motion-bundler/cli.rb
|
71
88
|
- lib/motion-bundler/config.rb
|
72
89
|
- lib/motion-bundler/device/boot.rb
|
73
90
|
- lib/motion-bundler/device/core_ext.rb
|
@@ -103,7 +120,7 @@ files:
|
|
103
120
|
- sample_app/mocks/httparty.rb
|
104
121
|
- sample_app/mocks/net/protocol.rb
|
105
122
|
- sample_app/mocks/openssl.rb
|
106
|
-
- sample_app/mocks/socket.rb
|
123
|
+
- sample_app/mocks/socket.so.rb
|
107
124
|
- sample_app/mocks/timeout.rb
|
108
125
|
- sample_app/resources/Icon.png
|
109
126
|
- sample_app/resources/Icon.pxm
|
@@ -146,6 +163,7 @@ files:
|
|
146
163
|
- test/lib/d/b/a/a.rb
|
147
164
|
- test/lib/d/b/b.rb
|
148
165
|
- test/lib/d/c.rb
|
166
|
+
- test/lib/e.rb
|
149
167
|
- test/mocks/net/http.rb
|
150
168
|
- test/mocks/psych_foo-0.1.0/psych/handler.rb
|
151
169
|
- test/mocks/yaml.rb
|
@@ -227,6 +245,7 @@ test_files:
|
|
227
245
|
- test/lib/d/b/a/a.rb
|
228
246
|
- test/lib/d/b/b.rb
|
229
247
|
- test/lib/d/c.rb
|
248
|
+
- test/lib/e.rb
|
230
249
|
- test/mocks/net/http.rb
|
231
250
|
- test/mocks/psych_foo-0.1.0/psych/handler.rb
|
232
251
|
- test/mocks/yaml.rb
|