My last PHP tutorial was about PHPUnit tests. Now let’s learn about the more elegant Ruby BDD/TDD framework, named rspec.
I’m using a newly installed Archlinux. First, install sstephenson’s Ruby Version Management software:
Now, build ruby the proper way:
Install bundler, the best way to define GEM requirements in project level:
Create the project directory and some initial files:
Edit Gemfile:
And Rakefile:
Install all required gems by typing: “bundle install”. Now, if you put “rake test” in command line, the test will run with no output (there are no test cases). Let’s create some application logic. I will re-implement my PHP Log class described before. Put this to test/log_spec.rb:
And to lib/log.rb:
As you can see, the rspec test examples have a very readable syntax:
But what is before(:all) and after(:all) does mean? Everything in the do-end block will execute once. Before starting testcase and after all test examples done in the file. You can also use the “:each” when you want to execute anything every time a test example run.
Some other assertions:
Feel free to try everything you want and define more “it must be work, should be true” sentences, run them and create bigger applications with team-players like you. Next, we will see “Cucumber”.
For an eCommerce business, few things are as unsettling as experiencing downtime on their website, which is essential for selling products. Downtime not only...
In the realm of technology, the term “software engineer” often conjures images of lines of code, intricate algorithms, and complex technical solutions. Howev...
I’ve been immersed in the world of Wayland on Linux since July. The journey hasn’t been entirely smooth, and I’ve found myself circling back to X11, which, s...
Comments