Skip to content

Commit

Permalink
Added OS detection for install generator
Browse files Browse the repository at this point in the history
system call for Windows and unit-tests for it. (#666)
  • Loading branch information
GeorgeGorbanev authored and justin808 committed Jan 18, 2017
1 parent 53af841 commit 0796bf4
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Contributors: please follow the recommendations outlined at [keepachangelog.com]

## [Unreleased]
*Please add entries here for your pull requests.*
### Fixed
- Added OS detection for install generator, system call for Windows and unit-tests for it. [#666](https://github.com/shakacode/react_on_rails/pull/666) by [GeorgeGorbanev](https://github.com/GeorgeGorbanev).

## [6.4.0] - 2017-1-12

Expand Down
4 changes: 2 additions & 2 deletions lib/generators/react_on_rails/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ def installation_prerequisites_met?
end

def missing_npm?
return false unless `which npm`.blank?
return false unless ReactOnRails::Utils.running_on_windows? ? `where npm`.blank? : `which npm`.blank?
error = "npm is required. Please install it before continuing. "
error << "https://www.npmjs.com/"
GeneratorMessages.add_error(error)
true
end

def missing_node?
return false unless `which node`.blank?
return false unless ReactOnRails::Utils.running_on_windows? ? `where node`.blank? : `which node`.blank?
error = "** nodejs is required. Please install it before continuing. "
error << "https://nodejs.org/en/"
GeneratorMessages.add_error(error)
Expand Down
4 changes: 4 additions & 0 deletions lib/react_on_rails/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ def self.default_server_bundle_js_file_path
ReactOnRails.configuration.server_bundle_js_file)
end

def self.running_on_windows?
(/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
end

module Required
def required(arg_name)
raise ArgumentError, "#{arg_name} is required"
Expand Down
64 changes: 64 additions & 0 deletions spec/react_on_rails/generators/install_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,68 @@
.to include(GeneratorMessages.format_info(expected))
end
end

context "detect existing bin-files on *nix" do
before(:all) { @install_generator = InstallGenerator.new }

specify "when node is exist" do
stub_const("RUBY_PLATFORM", "linux")
allow(@install_generator).to receive(:`).with("which node").and_return("/path/to/bin")
expect(@install_generator.send(:missing_node?)).to eq false
end

specify "when npm is exist" do
stub_const("RUBY_PLATFORM", "linux")
allow(@install_generator).to receive(:`).with("which npm").and_return("/path/to/bin")
expect(@install_generator.send(:missing_npm?)).to eq false
end
end

context "detect missing bin-files on *nix" do
before(:all) { @install_generator = InstallGenerator.new }

specify "when node is missing" do
stub_const("RUBY_PLATFORM", "linux")
allow(@install_generator).to receive(:`).with("which node").and_return("")
expect(@install_generator.send(:missing_node?)).to eq true
end

specify "when npm is missing" do
stub_const("RUBY_PLATFORM", "linux")
allow(@install_generator).to receive(:`).with("which npm").and_return("")
expect(@install_generator.send(:missing_npm?)).to eq true
end
end

context "detect existing bin-files on windows" do
before(:all) { @install_generator = InstallGenerator.new }

specify "when node is exist" do
stub_const("RUBY_PLATFORM", "mswin")
allow(@install_generator).to receive(:`).with("where node").and_return("/path/to/bin")
expect(@install_generator.send(:missing_node?)).to eq false
end

specify "when npm is exist" do
stub_const("RUBY_PLATFORM", "mswin")
allow(@install_generator).to receive(:`).with("where npm").and_return("/path/to/bin")
expect(@install_generator.send(:missing_npm?)).to eq false
end
end

context "detect missing bin-files on windows" do
before(:all) { @install_generator = InstallGenerator.new }

specify "when node is missing" do
stub_const("RUBY_PLATFORM", "mswin")
allow(@install_generator).to receive(:`).with("where node").and_return("")
expect(@install_generator.send(:missing_node?)).to eq true
end

specify "when npm is missing" do
stub_const("RUBY_PLATFORM", "mswin")
allow(@install_generator).to receive(:`).with("where npm").and_return("")
expect(@install_generator.send(:missing_npm?)).to eq true
end
end
end

0 comments on commit 0796bf4

Please sign in to comment.