Start Embedded MongoDB with RSpec? - ruby

Is there such thing as an embedded version of MongoDB suitable for use with RSpec, that can be started with a suite of tests?
In JavaLand, where I normally live when I'm not vacationing in the United States of Ruby, we are in the habit of starting portable embedded versions of database servers when we run tests, such as this Java-embeddable MongoDB.
Is there an equivalent for Ruby? Or do we always expect developers to have a local MongoDB running?

Currently, our replica set tests use a MongoConfig test tool to bring up RS members:
https://github.com/mongodb/mongo-ruby-driver/blob/1.x-stable/test/tools/mongo_config.rb
Check out this method for how to use it:
https://github.com/mongodb/mongo-ruby-driver/blob/1.x-stable/test/helpers/test_unit.rb#L38-L62
We don't use it for our non-replica set tests, but I don't see why you couldn't use it yourself. I also don't see anything about Rspec in particular that would make this difficult either.

Related

starting geoserver programmatically using java

I'm looking to run some integration tests with multiple geoserver instances and thought the best way would be to do setup and teardown programmatically.
Are there any simple examples of how this can be done?
You could start geoserver inside tomcat using {tomcat_home}/bin/startup.sh from command line (almost all programming languages let you run OS commands).
Now, for setup and data connections, your best chance is use Geoserver Rest API:
https://docs.geoserver.org/stable/en/user/rest/
If you want to replicate a same configuration/data setup for multiple geoserver instances, you could create a ready "data" directory with all your configurations and paste that directory on every geoserver instance you want.
The teardown step you can use {tomcat_home}/bin.shutdown.sh command.

Ruby Cucumber - Running using Cucumber::Runtime(config).run! - 'Officially supported'?

I have a test farm I'm making that can run Cucumber tests and will take the results and write to a database.
Instead of using backticks to run from the command line I'm considering this, which seemed to work rather well from an irb prompt:
config = {paths: ['.\\scenarios\\my.feature'], filters: [], tag_expressions: ['#open_print_pdf'],tag_limits: [], profiles: ['example'], require: []}
Cucumber::Runtime.new(Cucumber::Configuration.new(config)).run!
I like that I then get some objects that I can interrogate to write things I need to the db like:
steps
feature and scenario name
etc.
Before I considered this I was going to run using the JSON formatter, save the file, and then parse it, make it a hash and send to db.
Is the only supported way to run it through the command line. I find it useful to programmatically run it so I have everything I need without needing to do needless IO.
So, is running using Cucumber::Runtime(config).run! officially supported?

Store data in selenium webdriver

Im looking for a way to store data in selenium for use in future tests.
Im using jenkins, maven + selenium and testng.
How can i store some data, lets say i want to run test, get some data from website (weather forecast). Store it somewhere and next day run test to check if forecast match todays weather.
I can store it in txt file, and parse by regex but im sure there is better way to do it?
You have to consider what "selenium webdriver" is in this context. It is a Java app. It "exists" only when it is running. Once the run stops, it is purged from memory, including all data it held. If you are using JUnit or TestNG (as you specified), then this data is purged even more frequently: after every the class.
To accomplish what you are asking, you will need something external to your tests. You can certainly utilize a txt file as you suggested. A spreadsheet might do for your purposes. Most applications utilize an entire database.
You also mentioned Jenkins. This will make the external storage a more interesting problem, as Jenkins often purges the current working directory before each run.

Jenkins Integration/Unit Testing

My group will be implementing CI using Jenkins. As such, I want to make sure that any unit and/or integration tests we create integrate easily with Jenkins. We have several different technologies in our stack we are using from C++ code to Oracle PL/SQL packages to Groovy code. We want to develop test drivers (code that wraps and tests these individual code units) that we can integrate with Jenkins so that these tests are automatically run when we perform commits (git) as well as on a nightly basis. My question is, what are the best practices for writing these test drivers so that they will easily integrate with Jenkins when we implement it?
For example, we have have a PL/SQL stored procedure that we want to run tests against as part of our CI testing. I could write a bash shell script that wraps calls to it, I could write a Java program that calls it. Basically I could wrap it in anything. Then the next question is...is there some sort of standard for outputting results so that Jenkins can easily determine if the test passed or failed?
.is there some sort of standard for outputting results so that Jenkins
can easily determine if the test passed or failed?
If your test results are compliant with Junit results,jenkins have junit plugin which give you the better way for tracing test reports (result trend graph) and also test result archiving. converting ant test log to Junit format easier one.
useful links:
http://nose2.readthedocs.org/en/latest/plugins/junitxml.html
https://wiki.jenkins-ci.org/display/JENKINS/JUnit+Plugin
https://wiki.jenkins-ci.org/display/JENKINS/xUnit+Plugin
Jenkins and JUnit
Basically I could wrap it in anything.
I personally prefer to go with Java among your choices.because it give you better Api to create xml files
Use python unittest to wrap any of your tests.
Produce junit xml test results.
One easy way of getting any python unittest to write out junit is from command-line.
yum install pytest
And call your test script like this:
py.test --junitxml result.xml testscript.py
And in jenkins build configuration Post-build actions Add a "Publish JUnit test result report" action with result.xml and any more test result files you produce.
https://docs.python.org/2.7/library/unittest.html
This is just one way of producing junit xml results with python. There are a good few other methods either using unittest module or junitxml or others.

Embedded MongoDB instance?

I've been using MongoDB for a little tool that I'm building, but I have two problems that I don't know if I can "solve". Those problems are mainly related with having to start a MongoDB server (mongod).
The first is that I have to run two commands every time that I want to use it (mongod and my app's command) and the other is testing. For now, I'm using different collections for "production" and "test", but it would be better to have just an embedded / self-contained instance that I can start and drop whenever I want.
Is that possible? Or should I just use something else, like SQLite for that?
Thanks!
Another similar project is https://github.com/Softmotions/ejdb.
The query syntax is similar to mongodb.
We use this at work - https://github.com/flapdoodle-oss/embedmongo.flapdoodle.de - to fire up embedded Mongo for integration tests. Has worked really well.
I haven't tried it, but I just found this Ruby implementation of an embedded MongoDB: https://github.com/gdb/embedded-mongo

Resources