Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Checks that two values are same and "magically" replaces expected value with the actual in case the new behavior (and new actual value) is correct. Support two kind of arguments: string and code block.
This check works with both Test/Unit and RSpec. See documentation and examples below:
It is better to start with no expected value
assert_value "foo"
Then run tests as usual with "rake test". As a result you will see diff between expected and actual values:
Failure:
@@ -1,0, +1,1 @@
+foo
Accept the new value: yes to all, no to all, yes, no? [Y/N/y/n] (y):
If you accept the new value your test will be automatically modified to
assert_value "foo", <<-END
foo
END
assert_value can take code block as an argument. If executed block raises exception then exception message is returned as actual value:
assert_value do
nil+1
end
Run tests
Failure:
@@ -1,0, +1,1 @@
+Exception NoMethodError: undefined method `+' for nil:NilClass
Accept the new value: yes to all, no to all, yes, no? [Y/N/y/n] (y):
After the new value is accepted you get
assert_value(<<-END) do
Exception NoMethodError: undefined method `+' for nil:NilClass
END
nil + 1
end
Sometimes test string is too large to be inlined into the test source. Put it into the file instead:
assert_value "foo", log: 'test/log/reference.txt'
--no-interactive skips all questions and just reports failures
--autoaccept prints diffs and automatically accepts all new actual values
--no-canonicalize turns off expected and actual value canonicalization (see below for details)
Additional options can be passed during both single test file run and rake test run:
In Ruby 1.8:
ruby test/unit/foo_test.rb -- --autoaccept
rake test TESTOPTS="-- --autoaccept"
In Ruby 1.9:
ruby test/unit/foo_test.rb --autoaccept
rake test TESTOPTS="--autoaccept"
In specs you can either call assert_value directly or use "be_same_value_as" matcher:
describe "spec with be_same_value_as matcher" do
it "compares with inline value" do
expect("foo").to be_same_value_as <<-END
foo
END
end
it "compares with inline block" do
expect { "foo" }.to be_same_value_as <<-END
foo
END
end
it "compares with value in file" do
expect("foo").to be_same_value_as(:log => 'test/logs/assert_value_with_files.log.ref')
end
end
Before comparing expected and actual strings, assert_value canonicalizes both using these rules:
You can turn canonicalization off with --no-canonicalize option. This is useful when you need to regenerate expected test strings. To regenerate the whole test suite, run:
In Ruby 1.8:
rake test TESTOPTS="-- --no-canonicalize --autoaccept"
In Ruby 1.9:
rake test TESTOPTS="--no-canonicalize --autoaccept"
Framework / Ruby | 1.8.7 | 1.9.3 | 2.0+ |
---|---|---|---|
Test-Unit (bundled) | Yes | No | No |
Minitest (bundled) | No | Yes | No |
Test-Unit (latest) | No | No | Yes |
Minitest (latest) | No | No | Yes |
Rspec 2.99 | Yes | Yes | No |
Rspec (latest) | Yes | Yes | Yes |
One way to setup development environment using rbenv:
# compile ruby
rbenv install 2.3.0
# set local version of ruby under rbenv
rbenv local 2.3.0
# install bundler
gem install bundle
# configure bundler
bundle config --local path .bundle/gems
bundle config --local bin .bundle/bin # binstubs
bundle config # to see current settings
# below seems to be necessary, having a Gemfile in
# subdirectory like
# bundle config --local gemfile gemfiles/test-unit.bundled.gemfile
# breaks tests in old rubies
ln -s gemfiles/test-unit.bundled.gemfile Gemfile
# install gems
bundle install
Test-Unit and Minitest
bundle exec rake test
RSpec 2.99
bundle exec rspec test
RSpec 3+
bundle exec rake spec
gem build assert_value.gemspec
ls assert_value-*.gem
gem push assert_value-*.gem
FAQs
Unknown package
We found that assert_value demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.