
Security News
Follow-up and Clarification on Recent Malicious Ruby Gems Campaign
A clarification on our recent research investigating 60 malicious Ruby gems.
mrubyc-test is an unit test framework for mruby/c, supporting basic assertions, stub and mock.
Add this line to your application's Gemfile:
gem 'mrubyc-test'
And then execute:
$ bundle
Or install it yourself as:
$ gem install mrubyc-test
Assuming you are using mrubyc-utils to manage your project and rbenv to manage Ruby versions.
It means you have Mrubycfile
and .ruby-version
in the top directory of your project.
Besides, you have to locate mruby model files that are the target of testing like mrblib/models/class_name.rb
And read here about why you should use mrubyc-utils.
This is an example of ESP32 project:
~/your_project $ tree
.
├── Mrubycfile # Created by mrubyc-utils
├── .ruby-version # It should be mruby's version like 'mruby-3.0.0'
├── Makefile
├── build
├── components
├── main
├── mrblib
│ └── models # Place your model class files here
│ ├── class_name.rb # The testing target `ClassName`
│ └── my_class.rb # The testing target `MyClass`
│ └── loops
│ ├── main.rb # Loop script isn't covered by mrubyc-test. use mrubyc-debugger
│ └── sub.rb # Loop script isn't covered by mrubyc-test. use mrubyc-debugger
└── sdkconfig
In the same directory:
$ mrubyc-utils test init
Then, some directories and files will be created in your project. Now you can run test because a sample test code was also created.
$ mrubyc-utils test
You should get some assertion failures.
Take a look at test/sample_test.rb
to handle the failures and find how to write your own test.
def assertions
my_var = 1
assert_equal 1, my_var # => success
assert_not_equal 2, my_var # => success
assert_not_nil my_var # => success
end
Assuming you have a model file at mrblib/models/sample.rb
class Sample
attr_accessor :result
def do_something(arg)
@result = arg + still_not_defined_method
end
end
Then you can test #do_something
method without having #still_not_defind_method
like this:
def stub_case
sample_obj = Sample.new
stub(sample_obj).still_not_defined_method { ", so we are nice" }
sample_obj.do_something("Ruby is nice")
assert_equal 'Ruby is nice, so we are nice', sample_obj.result
end
mrblib/models/sample.rb
looks like this time:
class Sample
def do_other_thing
is_to_be_hit(1, 2) # Two args for example
end
end
You can test whether #is_to_be_hit(v1, v2)
method will be called:
def mock_case
sample_obj = Sample.new
mock(sample_obj).is_to_be_hit(2) # `2` should be count of parameters
sample_obj.do_other_thing
end
The API design and implementation of this gem is greatly inspired by test-unit. Thank the great work.
Bug reports and pull requests are welcome on GitHub at https://github.com/mrubyc/mrubyc-test. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
The gem is available as open source under the terms of the The 3-Clause BSD License.
Everyone interacting in the Mrubyc::Test project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.
FAQs
Unknown package
We found that mrubyc-test demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A clarification on our recent research investigating 60 malicious Ruby gems.
Security News
ESLint now supports parallel linting with a new --concurrency flag, delivering major speed gains and closing a 10-year-old feature request.
Research
/Security News
A malicious Go module posing as an SSH brute forcer exfiltrates stolen credentials to a Telegram bot controlled by a Russian-speaking threat actor.