Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions lib/listen/adapter/darwin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ module Adapter
# Adapter implementation for Mac OS X `FSEvents`.
#
class Darwin < Base
OS_REGEXP = /darwin(?<major_version>(1|2)\d+)/i
# Some ruby builds omit the version (--with-os-version-style=none).
OS_REGEXP = /\Adarwin(?<major_version>\d+)?/i

# The default delay between checking for changes.
DEFAULTS = { latency: 0.1 }.freeze
Expand All @@ -23,8 +24,11 @@ class Darwin < Base
EOS

def self.usable?
version = RbConfig::CONFIG['target_os'][OS_REGEXP, :major_version]
return false unless version
match = OS_REGEXP.match(RbConfig::CONFIG['target_os'])
return false unless match

version = match[:major_version]
return true if version.nil?
return true if version.to_i >= 13 # darwin13 is OS X 10.9

require 'rb-fsevent'
Expand Down
17 changes: 17 additions & 0 deletions spec/lib/listen/adapter/darwin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,23 @@
it { should be_usable }
end

context 'on darwin30 (a macOS newer than this gem)' do
before do
allow(RbConfig::CONFIG).to receive(:[]).and_return('darwin30')
end

it { should be_usable }
end

# ruby built with --with-os-version-style=none reports a bare 'darwin'.
context 'on a build with the version stripped from target_os' do
before do
allow(RbConfig::CONFIG).to receive(:[]).and_return('darwin')
end

it { should be_usable }
end

context 'on darwin10.0 (OS X Snow Leopard)' do
before do
allow(RbConfig::CONFIG).to receive(:[]).and_return('darwin10.0')
Expand Down