Join the DZone community and get the full member experience.Join For Free
In order to help a team mate, I recently gave it shot writing a Ruby gem, “angular-translate-rails". The idea is that if you are working inside a Ruby on Rails application and you would like to include an asset. That is done by acquiring it as gem. The main advantage is that you do not have to worry about maintaining it in your own code base, including its licenses. If you want to understand more about gems and how to create them, this is a great resource.
A spec to test the internals of the library are really not what was needed it. That seem to have been done well in the library itself. What I wanted to test was that the gem will do what it is supposed to do, i.e. deliver the asset to the application in the right place when included.
Scenario A. Create a vanilla rails application and make it use the gem. That is it! The steps are basically.
Scenario B. Here, if you created the gem as a standard Ruby module with default scaffolding, you will see a test directory with a dummy application. Think of this as a bundled application serving as part of an integration test that tries to mimic using the gem.
test 'can access angular-translate' do get '/assets/angular-translate.js' assert_response :success end
test "truth" do assert_kind_of Module, AngularTranslate::Rails end
The gem repo is here if you need to fork and play with it.
Opinions expressed by DZone contributors are their own.