README.md in assert_value-1.0 vs README.md in assert_value-1.1
- old
+ new
@@ -2,12 +2,14 @@
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.
-## String Example:
+This check works with both Test/Unit and RSpec. See documentation and examples below:
+## Testing String Values
+
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
@@ -22,13 +24,13 @@
assert_value "foo", <<-END
foo
END
-## Block Example:
+## Testing Block Values
-assert_value supports code block as argument. If executed block raises exception then
+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
@@ -46,12 +48,18 @@
Exception NoMethodError: undefined method `+' for nil:NilClass
END
nil + 1
end
-## Options:
+## Testing Values Stored in Files
+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'
+
+## Additional Test/Unit Options:
+
--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:
@@ -64,10 +72,33 @@
In Ruby 1.9:
ruby test/unit/foo_test.rb --autoaccept
rake test TESTOPTS="--autoaccept"
+## RSpec
+
+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
+
+
## Canonicalization:
Before comparing expected and actual strings, assert_value canonicalizes both using these rules:
- indentation is ignored (except for indentation relative to the first line of the expected/actual string)
@@ -88,9 +119,10 @@
rake test TESTOPTS="--no-canonicalize --autoaccept"
## Changelog
+- 1.1: RSpec support
- 1.0: Rename to assert_value
- 0.7: Support Ruby 1.9's MiniTest
- 0.6: Support test execution on Mac
- 0.5: Support code blocks to assert_same
- 0.4: Added support for code blocks as argument