Example of test that should be written by DEVELOPERS. This short post is about how ruby Dir class test proved that my heuristic about current folder feature was wrong.
Test tool that I am developing for one client has one simple feature, provide full file path where error happened. My heuristic was that
. will return same result, but I was wrong. rspec test helped me to test this heuristic.
Here is documentation for
Returns the path to the current working directory of this process as a string.
Returns Array of file paths that are present in folder.
Current working directory in Unix notation.
Documentation supported my heuristic. And they both represented same thing, but in different format:
expect(Pwd.new.list_ruby_files Dir.pwd).to eq ["/Users/karlosmid/repos/pwd/spec/pwd_spec.rb", "/Users/karlosmid/repos/pwd/pwd.rb"]
Full path versus call without explicitly setting parameter uses default value
expect(Pwd.new.list_ruby_files).to eq ["./spec/pwd_spec.rb", "./pwd.rb"]
This is what developer should test using testing framework:
Using unit tests, developer should test their heuristics about code they wrote and libraries/frameworks they use in that code.
Tester should care about their own heuristics.
Here is github repo pwd.
Also published on Medium.by