How can i populate database when using rspec

I'm using rspec to test my web services but when i looks in my database after each test ,i don't get anything in tables so please help me out to resolve this problem.

Here is my code:

**require 'rails_helper'

RSpec.describe "User management", :type => :request do

context "create users" do
  it "creates a user by supplying facebook_token" do
    headers = { "CONTENT_TYPE" => "application/json",
                "ACCEPT" => ""
    post "/api/users", '{ "user": { "facebook_user_token":"" } }', headers
    expect(response).to be_success



Basic principle while testing is each test should be independent. No test should depend on the other test.

If you want data in your tables to be used across tests then use

context "create users" do
  before :context do

Now the user will be available in all the examples inside the context block

Need Your Help

How to switch between ad networks randomly?


I have an app and I want to add advertisement from few companies, such as tapjoy, inneractive... How to make them to be changed randomly?

iOS ARC with when two objects need a pointer to the same thing

objective-c ios automatic-ref-counting

I'm going through my code to make sure that all of my properties have the proper weak/strong modifier and I ran across this situation which I don't know what to do with. Keep in mind that I'm fair...