Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Windows compatibility #666

Merged
Merged
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
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test for this. Use one of the alternate ways of discovering this information.

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