sass 3.1.21 → 3.2.0.alpha.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (180) hide show
  1. data/README.md +5 -4
  2. data/REVISION +1 -1
  3. data/Rakefile +6 -15
  4. data/VERSION +1 -1
  5. data/VERSION_NAME +1 -1
  6. data/lib/sass.rb +0 -1
  7. data/lib/sass/cache_stores/base.rb +1 -3
  8. data/lib/sass/cache_stores/filesystem.rb +0 -3
  9. data/lib/sass/css.rb +49 -145
  10. data/lib/sass/engine.rb +23 -47
  11. data/lib/sass/environment.rb +5 -30
  12. data/lib/sass/exec.rb +7 -30
  13. data/lib/sass/importers/base.rb +1 -2
  14. data/lib/sass/importers/filesystem.rb +13 -18
  15. data/lib/sass/less.rb +1 -1
  16. data/lib/sass/plugin.rb +8 -4
  17. data/lib/sass/plugin/compiler.rb +67 -93
  18. data/lib/sass/plugin/configuration.rb +2 -0
  19. data/lib/sass/plugin/staleness_checker.rb +4 -14
  20. data/lib/sass/repl.rb +3 -2
  21. data/lib/sass/script.rb +1 -0
  22. data/lib/sass/script/color.rb +9 -4
  23. data/lib/sass/script/funcall.rb +3 -16
  24. data/lib/sass/script/functions.rb +55 -98
  25. data/lib/sass/script/interpolation.rb +0 -9
  26. data/lib/sass/script/lexer.rb +4 -2
  27. data/lib/sass/script/list.rb +0 -8
  28. data/lib/sass/script/literal.rb +20 -5
  29. data/lib/sass/script/node.rb +0 -8
  30. data/lib/sass/script/number.rb +11 -35
  31. data/lib/sass/script/operation.rb +0 -16
  32. data/lib/sass/script/parser.rb +5 -12
  33. data/lib/sass/script/string_interpolation.rb +0 -9
  34. data/lib/sass/script/unary_operation.rb +0 -7
  35. data/lib/sass/script/variable.rb +1 -5
  36. data/lib/sass/scss/parser.rb +54 -191
  37. data/lib/sass/scss/rx.rb +3 -15
  38. data/lib/sass/scss/static_parser.rb +3 -3
  39. data/lib/sass/selector.rb +3 -15
  40. data/lib/sass/selector/abstract_sequence.rb +2 -11
  41. data/lib/sass/selector/comma_sequence.rb +3 -8
  42. data/lib/sass/selector/sequence.rb +11 -74
  43. data/lib/sass/selector/simple.rb +1 -7
  44. data/lib/sass/selector/simple_sequence.rb +8 -28
  45. data/lib/sass/shared.rb +5 -3
  46. data/lib/sass/tree/comment_node.rb +12 -25
  47. data/lib/sass/tree/debug_node.rb +1 -1
  48. data/lib/sass/tree/directive_node.rb +0 -5
  49. data/lib/sass/tree/each_node.rb +1 -1
  50. data/lib/sass/tree/extend_node.rb +1 -1
  51. data/lib/sass/tree/for_node.rb +2 -2
  52. data/lib/sass/tree/function_node.rb +1 -1
  53. data/lib/sass/tree/if_node.rb +14 -1
  54. data/lib/sass/tree/media_node.rb +4 -4
  55. data/lib/sass/tree/mixin_def_node.rb +1 -1
  56. data/lib/sass/tree/mixin_node.rb +2 -2
  57. data/lib/sass/tree/node.rb +26 -10
  58. data/lib/sass/tree/return_node.rb +1 -1
  59. data/lib/sass/tree/root_node.rb +1 -1
  60. data/lib/sass/tree/rule_node.rb +11 -9
  61. data/lib/sass/tree/variable_node.rb +1 -1
  62. data/lib/sass/tree/visitors/base.rb +1 -1
  63. data/lib/sass/tree/visitors/check_nesting.rb +36 -29
  64. data/lib/sass/tree/visitors/convert.rb +9 -16
  65. data/lib/sass/tree/visitors/cssize.rb +9 -40
  66. data/lib/sass/tree/visitors/perform.rb +23 -79
  67. data/lib/sass/tree/visitors/to_css.rb +21 -23
  68. data/lib/sass/tree/warn_node.rb +1 -1
  69. data/lib/sass/tree/while_node.rb +1 -1
  70. data/lib/sass/util.rb +9 -147
  71. data/lib/sass/version.rb +0 -14
  72. data/test/sass/cache_test.rb +0 -15
  73. data/test/sass/conversion_test.rb +8 -50
  74. data/test/sass/css2sass_test.rb +0 -33
  75. data/test/sass/engine_test.rb +32 -283
  76. data/test/sass/extend_test.rb +0 -315
  77. data/test/sass/functions_test.rb +23 -60
  78. data/test/sass/importer_test.rb +0 -110
  79. data/test/sass/more_results/more_import.css +2 -2
  80. data/test/sass/plugin_test.rb +13 -40
  81. data/test/sass/results/import.css +2 -2
  82. data/test/sass/results/import_charset.css +0 -1
  83. data/test/sass/results/import_charset_1_8.css +0 -1
  84. data/test/sass/results/import_charset_ibm866.css +0 -1
  85. data/test/sass/results/scss_import.css +2 -2
  86. data/test/sass/results/units.css +1 -1
  87. data/test/sass/script_conversion_test.rb +0 -2
  88. data/test/sass/script_test.rb +4 -28
  89. data/test/sass/scss/css_test.rb +1 -79
  90. data/test/sass/scss/scss_test.rb +16 -96
  91. data/test/sass/templates/import_charset.sass +0 -2
  92. data/test/sass/templates/import_charset_1_8.sass +0 -2
  93. data/test/sass/templates/import_charset_ibm866.sass +0 -2
  94. data/test/sass/test_helper.rb +1 -1
  95. data/test/sass/util_test.rb +0 -28
  96. data/test/test_helper.rb +0 -2
  97. data/vendor/{listen → fssm}/LICENSE +1 -1
  98. data/vendor/fssm/README.markdown +55 -0
  99. data/vendor/fssm/Rakefile +59 -0
  100. data/vendor/fssm/VERSION.yml +5 -0
  101. data/vendor/fssm/example.rb +9 -0
  102. data/vendor/fssm/fssm.gemspec +77 -0
  103. data/vendor/fssm/lib/fssm.rb +33 -0
  104. data/vendor/fssm/lib/fssm/backends/fsevents.rb +36 -0
  105. data/vendor/fssm/lib/fssm/backends/inotify.rb +26 -0
  106. data/vendor/fssm/lib/fssm/backends/polling.rb +25 -0
  107. data/vendor/fssm/lib/fssm/backends/rubycocoa/fsevents.rb +131 -0
  108. data/vendor/fssm/lib/fssm/monitor.rb +26 -0
  109. data/vendor/fssm/lib/fssm/path.rb +91 -0
  110. data/vendor/fssm/lib/fssm/pathname.rb +502 -0
  111. data/vendor/fssm/lib/fssm/state/directory.rb +57 -0
  112. data/vendor/fssm/lib/fssm/state/file.rb +24 -0
  113. data/vendor/fssm/lib/fssm/support.rb +63 -0
  114. data/vendor/fssm/lib/fssm/tree.rb +176 -0
  115. data/vendor/fssm/profile/prof-cache.rb +40 -0
  116. data/vendor/fssm/profile/prof-fssm-pathname.html +1231 -0
  117. data/vendor/fssm/profile/prof-pathname.rb +68 -0
  118. data/vendor/fssm/profile/prof-plain-pathname.html +988 -0
  119. data/vendor/fssm/profile/prof.html +2379 -0
  120. data/vendor/fssm/spec/path_spec.rb +75 -0
  121. data/vendor/fssm/spec/root/duck/quack.txt +0 -0
  122. data/vendor/fssm/spec/root/file.css +0 -0
  123. data/vendor/fssm/spec/root/file.rb +0 -0
  124. data/vendor/fssm/spec/root/file.yml +0 -0
  125. data/vendor/fssm/spec/root/moo/cow.txt +0 -0
  126. data/vendor/fssm/spec/spec_helper.rb +14 -0
  127. metadata +246 -281
  128. data/VERSION_DATE +0 -1
  129. data/lib/sass/logger.rb +0 -15
  130. data/lib/sass/logger/base.rb +0 -32
  131. data/lib/sass/logger/log_level.rb +0 -49
  132. data/lib/sass/tree/visitors/deep_copy.rb +0 -87
  133. data/lib/sass/tree/visitors/extend.rb +0 -42
  134. data/lib/sass/tree/visitors/set_options.rb +0 -97
  135. data/lib/sass/util/multibyte_string_scanner.rb +0 -134
  136. data/test/Gemfile +0 -4
  137. data/test/Gemfile.lock +0 -19
  138. data/test/sass/fixtures/test_staleness_check_across_importers.css +0 -1
  139. data/test/sass/fixtures/test_staleness_check_across_importers.scss +0 -1
  140. data/test/sass/logger_test.rb +0 -58
  141. data/test/sass/templates/_double_import_loop2.sass +0 -1
  142. data/test/sass/templates/bork5.sass +0 -3
  143. data/test/sass/templates/double_import_loop1.sass +0 -1
  144. data/test/sass/templates/nested_bork5.sass +0 -2
  145. data/test/sass/templates/single_import_loop.sass +0 -1
  146. data/test/sass/util/multibyte_string_scanner_test.rb +0 -147
  147. data/vendor/listen/CHANGELOG.md +0 -147
  148. data/vendor/listen/Gemfile +0 -23
  149. data/vendor/listen/Guardfile +0 -8
  150. data/vendor/listen/README.md +0 -312
  151. data/vendor/listen/Rakefile +0 -47
  152. data/vendor/listen/Vagrantfile +0 -96
  153. data/vendor/listen/lib/listen.rb +0 -38
  154. data/vendor/listen/lib/listen/adapter.rb +0 -167
  155. data/vendor/listen/lib/listen/adapters/darwin.rb +0 -84
  156. data/vendor/listen/lib/listen/adapters/linux.rb +0 -110
  157. data/vendor/listen/lib/listen/adapters/polling.rb +0 -66
  158. data/vendor/listen/lib/listen/adapters/windows.rb +0 -81
  159. data/vendor/listen/lib/listen/directory_record.rb +0 -318
  160. data/vendor/listen/lib/listen/listener.rb +0 -203
  161. data/vendor/listen/lib/listen/multi_listener.rb +0 -121
  162. data/vendor/listen/lib/listen/turnstile.rb +0 -28
  163. data/vendor/listen/lib/listen/version.rb +0 -3
  164. data/vendor/listen/listen.gemspec +0 -26
  165. data/vendor/listen/spec/listen/adapter_spec.rb +0 -142
  166. data/vendor/listen/spec/listen/adapters/darwin_spec.rb +0 -31
  167. data/vendor/listen/spec/listen/adapters/linux_spec.rb +0 -41
  168. data/vendor/listen/spec/listen/adapters/polling_spec.rb +0 -68
  169. data/vendor/listen/spec/listen/adapters/windows_spec.rb +0 -24
  170. data/vendor/listen/spec/listen/directory_record_spec.rb +0 -1138
  171. data/vendor/listen/spec/listen/listener_spec.rb +0 -155
  172. data/vendor/listen/spec/listen/multi_listener_spec.rb +0 -156
  173. data/vendor/listen/spec/listen/turnstile_spec.rb +0 -56
  174. data/vendor/listen/spec/listen_spec.rb +0 -73
  175. data/vendor/listen/spec/spec_helper.rb +0 -18
  176. data/vendor/listen/spec/support/adapter_helper.rb +0 -716
  177. data/vendor/listen/spec/support/directory_record_helper.rb +0 -55
  178. data/vendor/listen/spec/support/fixtures_helper.rb +0 -29
  179. data/vendor/listen/spec/support/listeners_helper.rb +0 -144
  180. data/vendor/listen/spec/support/platform_helper.rb +0 -11
@@ -1,203 +0,0 @@
1
- require 'pathname'
2
-
3
- module Listen
4
- class Listener
5
- attr_reader :directory, :directory_record, :adapter
6
-
7
- # The default value for using relative paths in the callback.
8
- DEFAULT_TO_RELATIVE_PATHS = false
9
-
10
- # Initializes the directory listener.
11
- #
12
- # @param [String] directory the directory to listen to
13
- # @param [Hash] options the listen options
14
- # @option options [Regexp] ignore a pattern for ignoring paths
15
- # @option options [Regexp] filter a pattern for filtering paths
16
- # @option options [Float] latency the delay between checking for changes in seconds
17
- # @option options [Boolean] relative_paths whether or not to use relative-paths in the callback
18
- # @option options [Boolean] force_polling whether to force the polling adapter or not
19
- # @option options [String, Boolean] polling_fallback_message to change polling fallback message or remove it
20
- #
21
- # @yield [modified, added, removed] the changed files
22
- # @yieldparam [Array<String>] modified the list of modified files
23
- # @yieldparam [Array<String>] added the list of added files
24
- # @yieldparam [Array<String>] removed the list of removed files
25
- #
26
- def initialize(directory, options = {}, &block)
27
- @block = block
28
- @directory = Pathname.new(directory).realpath.to_s
29
- @directory_record = DirectoryRecord.new(@directory)
30
- @use_relative_paths = DEFAULT_TO_RELATIVE_PATHS
31
-
32
- @use_relative_paths = options.delete(:relative_paths) if options[:relative_paths]
33
- @directory_record.ignore(*options.delete(:ignore)) if options[:ignore]
34
- @directory_record.filter(*options.delete(:filter)) if options[:filter]
35
-
36
- @adapter_options = options
37
- end
38
-
39
- # Starts the listener by initializing the adapter and building
40
- # the directory record concurrently, then it starts the adapter to watch
41
- # for changes.
42
- #
43
- # @param [Boolean] blocking whether or not to block the current thread after starting
44
- #
45
- def start(blocking = true)
46
- t = Thread.new { @directory_record.build }
47
- @adapter = initialize_adapter
48
- t.join
49
- @adapter.start(blocking)
50
- end
51
-
52
- # Stops the listener.
53
- #
54
- def stop
55
- @adapter.stop
56
- end
57
-
58
- # Pauses the listener.
59
- #
60
- # @return [Listen::Listener] the listener
61
- #
62
- def pause
63
- @adapter.paused = true
64
- self
65
- end
66
-
67
- # Unpauses the listener.
68
- #
69
- # @return [Listen::Listener] the listener
70
- #
71
- def unpause
72
- @directory_record.build
73
- @adapter.paused = false
74
- self
75
- end
76
-
77
- # Returns whether the listener is paused or not.
78
- #
79
- # @return [Boolean] adapter paused status
80
- #
81
- def paused?
82
- !!@adapter && @adapter.paused == true
83
- end
84
-
85
- # Adds ignoring patterns to the listener.
86
- #
87
- # @param (see Listen::DirectoryRecord#ignore)
88
- #
89
- # @return [Listen::Listener] the listener
90
- #
91
- def ignore(*regexps)
92
- @directory_record.ignore(*regexps)
93
- self
94
- end
95
-
96
- # Adds filtering patterns to the listener.
97
- #
98
- # @param (see Listen::DirectoryRecord#filter)
99
- #
100
- # @return [Listen::Listener] the listener
101
- #
102
- def filter(*regexps)
103
- @directory_record.filter(*regexps)
104
- self
105
- end
106
-
107
- # Sets the latency for the adapter. This is a helper method
108
- # to simplify changing the latency directly from the listener.
109
- #
110
- # @example Wait 0.5 seconds each time before checking changes
111
- # latency 0.5
112
- #
113
- # @param [Float] seconds the amount of delay, in seconds
114
- #
115
- # @return [Listen::Listener] the listener
116
- #
117
- def latency(seconds)
118
- @adapter_options[:latency] = seconds
119
- self
120
- end
121
-
122
- # Sets whether the use of the polling adapter
123
- # should be forced or not.
124
- #
125
- # @example Forcing the use of the polling adapter
126
- # force_polling true
127
- #
128
- # @param [Boolean] value whether to force the polling adapter or not
129
- #
130
- # @return [Listen::Listener] the listener
131
- #
132
- def force_polling(value)
133
- @adapter_options[:force_polling] = value
134
- self
135
- end
136
-
137
- # Sets whether the paths in the callback should be
138
- # relative or absolute.
139
- #
140
- # @example Enabling relative paths in the callback
141
- # relative_paths true
142
- #
143
- # @param [Boolean] value whether to enable relative paths in the callback or not
144
- #
145
- # @return [Listen::Listener] the listener
146
- #
147
- def relative_paths(value)
148
- @use_relative_paths = value
149
- self
150
- end
151
-
152
- # Defines a custom polling fallback message of disable it.
153
- #
154
- # @example Disabling the polling fallback message
155
- # polling_fallback_message false
156
- #
157
- # @param [String, Boolean] value to change polling fallback message or remove it
158
- #
159
- # @return [Listen::Listener] the listener
160
- #
161
- def polling_fallback_message(value)
162
- @adapter_options[:polling_fallback_message] = value
163
- self
164
- end
165
-
166
- # Sets the callback that gets called on changes.
167
- #
168
- # @example Assign a callback to be called on changes
169
- # callback = lambda { |modified, added, removed| ... }
170
- # change &callback
171
- #
172
- # @param [Proc] block the callback proc
173
- #
174
- # @return [Listen::Listener] the listener
175
- #
176
- def change(&block) # modified, added, removed
177
- @block = block
178
- self
179
- end
180
-
181
- # Runs the callback passing it the changes if there are any.
182
- #
183
- # @param (see Listen::DirectoryRecord#fetch_changes)
184
- #
185
- def on_change(directories, options = {})
186
- changes = @directory_record.fetch_changes(directories, options.merge(
187
- :relative_paths => @use_relative_paths
188
- ))
189
- unless changes.values.all? { |paths| paths.empty? }
190
- @block.call(changes[:modified],changes[:added],changes[:removed])
191
- end
192
- end
193
-
194
- private
195
-
196
- # Initializes an adapter passing it the callback and adapters' options.
197
- #
198
- def initialize_adapter
199
- callback = lambda { |changed_dirs, options| self.on_change(changed_dirs, options) }
200
- Adapter.select_and_initialize(@directory, @adapter_options, &callback)
201
- end
202
- end
203
- end
@@ -1,121 +0,0 @@
1
- module Listen
2
- class MultiListener < Listener
3
- attr_reader :directories, :directories_records, :adapter
4
-
5
- # Initializes the multiple directories listener.
6
- #
7
- # @param [String] directories the directories to listen to
8
- # @param [Hash] options the listen options
9
- # @option options [Regexp] ignore a pattern for ignoring paths
10
- # @option options [Regexp] filter a pattern for filtering paths
11
- # @option options [Float] latency the delay between checking for changes in seconds
12
- # @option options [Boolean] force_polling whether to force the polling adapter or not
13
- # @option options [String, Boolean] polling_fallback_message to change polling fallback message or remove it
14
- #
15
- # @yield [modified, added, removed] the changed files
16
- # @yieldparam [Array<String>] modified the list of modified files
17
- # @yieldparam [Array<String>] added the list of added files
18
- # @yieldparam [Array<String>] removed the list of removed files
19
- #
20
- def initialize(*args, &block)
21
- options = args.last.is_a?(Hash) ? args.pop : {}
22
- directories = args
23
-
24
- @block = block
25
- @directories = directories.map { |d| Pathname.new(d).realpath.to_s }
26
- @directories_records = @directories.map { |d| DirectoryRecord.new(d) }
27
-
28
- ignore(*options.delete(:ignore)) if options[:ignore]
29
- filter(*options.delete(:filter)) if options[:filter]
30
-
31
- @adapter_options = options
32
- end
33
-
34
- # Starts the listener by initializing the adapter and building
35
- # the directory record concurrently, then it starts the adapter to watch
36
- # for changes.
37
- #
38
- # @param [Boolean] blocking whether or not to block the current thread after starting
39
- #
40
- def start(blocking = true)
41
- t = Thread.new { @directories_records.each { |r| r.build } }
42
- @adapter = initialize_adapter
43
- t.join
44
- @adapter.start(blocking)
45
- end
46
-
47
- # Unpauses the listener.
48
- #
49
- # @return [Listen::Listener] the listener
50
- #
51
- def unpause
52
- @directories_records.each { |r| r.build }
53
- @adapter.paused = false
54
- self
55
- end
56
-
57
- # Adds ignored paths to the listener.
58
- #
59
- # @param (see Listen::DirectoryRecord#ignore)
60
- #
61
- # @return [Listen::Listener] the listener
62
- #
63
- def ignore(*paths)
64
- @directories_records.each { |r| r.ignore(*paths) }
65
- self
66
- end
67
-
68
- # Adds file filters to the listener.
69
- #
70
- # @param (see Listen::DirectoryRecord#filter)
71
- #
72
- # @return [Listen::Listener] the listener
73
- #
74
- def filter(*regexps)
75
- @directories_records.each { |r| r.filter(*regexps) }
76
- self
77
- end
78
-
79
- # Runs the callback passing it the changes if there are any.
80
- #
81
- # @param (see Listen::DirectoryRecord#fetch_changes)
82
- #
83
- def on_change(directories_to_search, options = {})
84
- changes = fetch_records_changes(directories_to_search, options)
85
- unless changes.values.all? { |paths| paths.empty? }
86
- @block.call(changes[:modified],changes[:added],changes[:removed])
87
- end
88
- end
89
-
90
- private
91
-
92
- # Initializes an adapter passing it the callback and adapters' options.
93
- #
94
- def initialize_adapter
95
- callback = lambda { |changed_dirs, options| self.on_change(changed_dirs, options) }
96
- Adapter.select_and_initialize(@directories, @adapter_options, &callback)
97
- end
98
-
99
- # Returns the sum of all the changes to the directories records
100
- #
101
- # @param (see Listen::DirectoryRecord#fetch_changes)
102
- #
103
- # @return [Hash] the changes
104
- #
105
- def fetch_records_changes(directories_to_search, options)
106
- @directories_records.inject({}) do |h, r|
107
- # directory records skips paths outside their range, so passing the
108
- # whole `directories` array is not a problem.
109
- record_changes = r.fetch_changes(directories_to_search, options.merge(:relative_paths => DEFAULT_TO_RELATIVE_PATHS))
110
-
111
- if h.empty?
112
- h.merge!(record_changes)
113
- else
114
- h.each { |k, v| h[k] += record_changes[k] }
115
- end
116
-
117
- h
118
- end
119
- end
120
- end
121
- end
@@ -1,28 +0,0 @@
1
- module Listen
2
- # Allows two threads to wait on eachother.
3
- #
4
- # @note Only two threads can be used with this Turnstile
5
- # because of the current implementation.
6
- class Turnstile
7
-
8
- # Initialize the turnstile.
9
- #
10
- def initialize
11
- # Until ruby offers semahpores, only queues can be used
12
- # to implement a turnstile.
13
- @q = Queue.new
14
- end
15
-
16
- # Blocks the current thread until a signal is received.
17
- #
18
- def wait
19
- @q.pop if @q.num_waiting == 0
20
- end
21
-
22
- # Unblocks the waiting thread if there is one.
23
- #
24
- def signal
25
- @q.push :dummy if @q.num_waiting == 1
26
- end
27
- end
28
- end
@@ -1,3 +0,0 @@
1
- module Listen
2
- VERSION = '0.4.7'
3
- end
@@ -1,26 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path('../lib', __FILE__)
3
- require 'listen/version'
4
-
5
- Gem::Specification.new do |s|
6
- s.name = 'listen'
7
- s.version = Listen::VERSION
8
- s.platform = Gem::Platform::RUBY
9
- s.authors = ['Thibaud Guillaume-Gentil', 'Maher Sallam']
10
- s.email = ['thibaud@thibaud.me', 'maher@sallam.me']
11
- s.homepage = 'https://github.com/guard/listen'
12
- s.summary = 'Listen to file modifications'
13
- s.description = 'The Listen gem listens to file modifications and notifies you about the changes. Works everywhere!'
14
-
15
- s.required_rubygems_version = '>= 1.3.6'
16
- s.rubyforge_project = 'listen'
17
-
18
- s.add_dependency 'rb-fsevent', '~> 0.9.1'
19
- s.add_dependency 'rb-inotify', '~> 0.8.8'
20
- s.add_dependency 'rb-fchange', '~> 0.0.5'
21
-
22
- s.add_development_dependency 'bundler'
23
-
24
- s.files = Dir.glob('{lib}/**/*') + %w[CHANGELOG.md LICENSE README.md]
25
- s.require_path = 'lib'
26
- end
@@ -1,142 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Listen::Adapter do
4
- subject { described_class.new('dir') }
5
-
6
- describe '#initialize' do
7
- it 'sets the latency to the default one' do
8
- subject.latency.should eq described_class::DEFAULT_LATENCY
9
- end
10
-
11
- it 'accepts a single directory to watch' do
12
- described_class.new('dir').directories = %w{dir}
13
- end
14
-
15
- it 'accepts multiple directories to watch' do
16
- described_class.new(%w{dir1 dir2}).directories.should eq %w{dir1 dir2}
17
- end
18
- end
19
-
20
- describe ".select_and_initialize" do
21
- before do
22
- Listen::Adapters::Darwin.stub(:usable_and_works?) { false }
23
- Listen::Adapters::Linux.stub(:usable_and_works?) { false }
24
- Listen::Adapters::Windows.stub(:usable_and_works?) { false }
25
- end
26
-
27
- context "with no specific adapter usable" do
28
- it "returns Listen::Adapters::Polling instance" do
29
- Kernel.stub(:warn)
30
- Listen::Adapters::Polling.should_receive(:new).with('dir', {})
31
- described_class.select_and_initialize('dir')
32
- end
33
-
34
- it "warns with the default polling fallback message" do
35
- Kernel.should_receive(:warn).with(Listen::Adapter::POLLING_FALLBACK_MESSAGE)
36
- described_class.select_and_initialize('dir')
37
- end
38
-
39
- context "with custom polling_fallback_message option" do
40
- it "warns with the custom polling fallback message" do
41
- Kernel.should_receive(:warn).with('custom')
42
- described_class.select_and_initialize('dir', :polling_fallback_message => 'custom')
43
- end
44
- end
45
-
46
- context "with polling_fallback_message to false" do
47
- it "doesn't warn with a polling fallback message" do
48
- Kernel.should_not_receive(:warn)
49
- described_class.select_and_initialize('dir', :polling_fallback_message => false)
50
- end
51
- end
52
- end
53
-
54
- context "on Mac OX >= 10.6" do
55
- before { Listen::Adapters::Darwin.stub(:usable_and_works?) { true } }
56
-
57
- it "uses Listen::Adapters::Darwin" do
58
- Listen::Adapters::Darwin.should_receive(:new).with('dir', {})
59
- described_class.select_and_initialize('dir')
60
- end
61
-
62
- context 'when the use of the polling adapter is forced' do
63
- it 'uses Listen::Adapters::Polling' do
64
- Listen::Adapters::Polling.should_receive(:new).with('dir', {})
65
- described_class.select_and_initialize('dir', :force_polling => true)
66
- end
67
- end
68
- end
69
-
70
- context "on Linux" do
71
- before { Listen::Adapters::Linux.stub(:usable_and_works?) { true } }
72
-
73
- it "uses Listen::Adapters::Linux" do
74
- Listen::Adapters::Linux.should_receive(:new).with('dir', {})
75
- described_class.select_and_initialize('dir')
76
- end
77
-
78
- context 'when the use of the polling adapter is forced' do
79
- it 'uses Listen::Adapters::Polling' do
80
- Listen::Adapters::Polling.should_receive(:new).with('dir', {})
81
- described_class.select_and_initialize('dir', :force_polling => true)
82
- end
83
- end
84
- end
85
-
86
- context "on Windows" do
87
- before { Listen::Adapters::Windows.stub(:usable_and_works?) { true } }
88
-
89
- it "uses Listen::Adapters::Windows" do
90
- Listen::Adapters::Windows.should_receive(:new).with('dir', {})
91
- described_class.select_and_initialize('dir')
92
- end
93
-
94
- context 'when the use of the polling adapter is forced' do
95
- it 'uses Listen::Adapters::Polling' do
96
- Listen::Adapters::Polling.should_receive(:new).with('dir', {})
97
- described_class.select_and_initialize('dir', :force_polling => true)
98
- end
99
- end
100
- end
101
- end
102
-
103
- [Listen::Adapters::Darwin, Listen::Adapters::Linux, Listen::Adapters::Windows].each do |adapter_class|
104
- if adapter_class.usable?
105
- describe '.usable_and_works?' do
106
- it 'checks if the adapter is usable' do
107
- adapter_class.stub(:works?)
108
- adapter_class.should_receive(:usable?)
109
- adapter_class.usable_and_works?('dir')
110
- end
111
-
112
- context 'with one directory' do
113
- it 'tests if that directory actually work' do
114
- fixtures do |path|
115
- adapter_class.should_receive(:works?).with(path, anything).and_return(true)
116
- adapter_class.usable_and_works?(path)
117
- end
118
- end
119
- end
120
-
121
- context 'with multiple directories' do
122
- it 'tests if each directory passed does actually work' do
123
- fixtures(3) do |path1, path2, path3|
124
- adapter_class.should_receive(:works?).exactly(3).times.with do |path, options|
125
- [path1, path2, path3].include? path
126
- end.and_return(true)
127
- adapter_class.usable_and_works?([path1, path2, path3])
128
- end
129
- end
130
- end
131
- end
132
-
133
- describe '.works?' do
134
- it 'does work' do
135
- fixtures do |path|
136
- adapter_class.works?(path).should be_true
137
- end
138
- end
139
- end
140
- end
141
- end
142
- end