massive refactoring of rspec tests

Using a lot of rspec shared_examples to minimize redundant code.