# Configuring RSpec

The following assumes that you've generated a middleman project using the its CLI `middleman init your_project_name`

## Update your Gemfile

Add the following gems to your `Gemfile` and run `bundle install`

```ruby
group :development, :test do
  gem 'capybara'
  gem 'pry'
  gem 'pry-byebug'
  gem 'rspec'
end
```

## Setup RSpec

From your terminal, navigate to your project directory and initialize RSpec config files for your project with the following command

`rspec --init`

Update the `.rspec` file to have the following code

```ruby
--format documentation
--color
--require spec_helper
```

Then remove all content in spec/spec\_helper.rb and replace with the following

```ruby
require 'rspec'
require 'capybara/rspec'

require 'middleman-core'
require 'middleman-core/rack'
require 'middleman-autoprefixer'
require 'middleman-livereload'

middleman_app = ::Middleman::Application.new

Capybara.app = ::Middleman::Rack.new(middleman_app).to_app do
  set :root, File.expand_path(File.join(File.dirname(FILE), '..'))
  set :environment, :development
  set :show_exceptions, false
end
```

With this in place we should now be ready to write our first spec

## Feature specs

Most of the specs you'll be writing for a middleman app will be feature specs that test for certain things to be visible on the page. Below is a sample feature spec that checks if projects are listed on the index page

```ruby
describe 'Index Page', type: :feature do
  it 'displays project list' do
    expect(page).to have_css '.projects'

    within '.projects' do
      expect(page).to have_content 'My First Website'
      expect(page).to have_content 'FizzBuzz'
    end
  end
end
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://craftacademy.gitbook.io/coding-as-a-craft-2-0/configuring-rspec.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
