Unable to include file in the spec file

I am trying to write an RSpec test for a ruby project(Sketchup plugin) but I am facing an issue with the require.

Below is how my folder is structured

In my smoke_tests_spec.rb

require "main_folder/subfolder1/file_to_test.rb"

When I run the rspec using rspec-core/rspec from the root directory I get the following error

Failure/Error: require "main_folder/subfolder1/file_to_test.rb"

  cannot load such file -- main_folder/subfolder1/file_to_test.rb

But I do require <absolute_path to file_to_test.rb> the load error goes away but I get a different error. Basically in all our files we use Sketchup::requirenow rspec will complain it does not know what isSketchup` how to get around this problem?

Sounds like the files you want the rspec tests to test isn’t on the load path.

You can’t test a SketchUp extension outside of SketchUp. A normal Ruby installation have no connection to Ruby in SketchUp.

We provide TestUp as a wrapper on top of Minitest to run tests for SketchUp extensions inside of SketchUp: GitHub - SketchUp/testup-2: TestUp 2 for SketchUp - A GUI wrapper for running Minitest in SketchUp

1 Like

I don’t really want to test any SketchUp features. We have created the plugin in such a way that there is a certain part(we call it smart_engine) that does not use SketchUp, it contains only business logic and I want to write tests for that.

In that case, you can’t be using Sketchup::require, as the Sketchup module does not exist in standard Ruby.


Just out of curiosity, what exactly is the difference between SketchUp::require and just require?

For Sketchup::require, you supply only the base name of the file, and it looks for extensions .rbe, .rbs, and.rb in that order. For the encrypted versions, it invokes the appropriate decryption loader to obtain plain Ruby to load.

1 Like

… also, within the SketchUp Ruby environment, the path to several SketchUp version specific “Plugins” directories have been pushed onto the global $LOAD_PATH ($:) array so that relative paths (to an extension loader script, the 2nd constructor argument) can be resolved to a full path by both Sketchup::require or Kernel#require.

The appending of SketchUp “Plugins” paths will not happen outside SketchUp in a “plain-Jane” system Ruby process.

I ended up writing Testup2 test.
Q1: Is there a feature for writing a theory test.
Q2: Is there a better way to compare two JSON data. Right now I am comparing them just as a plain string.

Edit: I figured out the json compare but please respond to question 1.

CC: @tt_su , @DanRathbun

I do not know the answer to Q1 as I am not a Test unit kind of person.

TestUp is a GUI wrapper on top of Minitest; GitHub - minitest/minitest: minitest provides a complete suite of testing facilities supporting TDD, BDD, mocking, and benchmarking.
Any features available is coming directly from Minitest. I’ve not heard of “theory test” before, so I’m not sure if Minitest cater for that.