> ## Content Index
> Fetch the complete content index at: https://www.kenst.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# When to use a Gemfile
- URL: https://www.kenst.com/when-to-use-a-gemfile/
- Published: 2015-05-31T20:53:00.000Z
- Updated: 2022-06-09T23:59:48.000Z
- Author: Chris Kenst
- Tags: RSpec, Ruby, Selenium, Test Techniques, Tools

I’ve been building a GUI acceptance test automation suite locally in Ruby using the [RSpec framework](http://en.wikipedia.org/wiki/RSpec?ref=kenst.com). When it was time to get the tests running remotely on Sauce Labs, I ran into the following error:

`` RSpec::Core::ExampleGroup::WrongScopeError: `example` is not available from within an example (e.g. an `it` block) or from constructs that run in the scope of an example (e.g. `before`, `let`, etc). It is only available on an example group (e.g. a `describe` or `context` block).  
occurred at /usr/local/rvm/gems/ruby-2.1.2/gems/rspec-core-3.2.2/lib/rspec/core/example_group.rb:642:in `method_missing' ``

It took a few minutes debugging before I spotted the error:

../gems/ruby-2.1.2/gems/rspec-core-3.2.2/lib/rspec/core/..

Source of problem: My remote tests were using a different version of RSpec than I was locally. Solution: Create a Gemfile to specify the version of using Rspec I’m using.

Since I didn’t realize I needed a Gemfile my question was, in general, when should someone use a Gemfile? According to the [manual](http://bundler.io/man/gemfile.5.html?ref=kenst.com), a Gemfile

> describes the gem dependencies required to execute associated Ruby code. Place the Gemfile in the root of the directory containing the associated code.

For example, in this context, I would place a Gemfile into any folder where I specifically want to call tests to run. In my case that meant a few specific locations:

- At the root of the folder – where I run the whole suite of tests
- In the /spec/ folder – where I typically run tests at an individual level

At a minimum I’d specify:

- A Global Source
- Each Gem I use locally that Sauce Labs will need to use

In the end it might look something like this:  

Test, adapt, and re-test.