I want to test if top\_users eq User.top\_users in my rspec controller. 
How do i access the format.csv? I need something like:

```rb
it "format csv" do
  get :index, format: :csv
  # expect(something)……
end

```

Later want to test the csv: if file format is correct, without saving/downloading it.

Controller:

```rb
def index
  respond_to do |format|  
    format.csv do
      top_users = User.top_users

      send_data(
        top_users.to_csv,
        filename: "top-users-#{Time.zone.today}.csv"
      )
    end
  end
end

```

Model:

```rb
def self.to_csv
  CSV.generate(headers: true) do |csv|
    csv << [‘one’, ‘two’]

    all.each do |user|
      csv << user.csv_data
    end
  end
end

```

csv\_data is: [user.name, user.email] or so…