hello message with passing name" do result = HelloMessage.new("Samnang").result expect(result).to eq("Hello Samnang!") end end context "without passing name" do it "returns the default of hello message" do result = HelloMessage.new.result expect(result).to eq("Hello World!") end end end
end skip "skip with inline method call" do end it "skip with tag skip", skip: "give a reason" do end it "skip with method call" do skip("give a reason") end end
type: :model do describe "validations" do subject { build(:user) } it { is_expected.to validate_presence_of(:email) } it { is_expected.to validate_uniqueness_of(:email) } it { is_expected.to validate_length_of(:username).is_at_least(3) } it { is_expected.to validate_uniqueness_of(:username) } end end
actual % expected == 0 end end RSpec.describe 9 do it { is_expected.to be_a_multiple_of(3) } end RSpec.describe 9 do it { is_expected.not_to be_a_multiple_of(4) } end
].shuffle.first end end RSpec.describe StopLight, "#color" do let(:light) { StopLight.new } it "is green, yellow or red" do expect(light.color).to eq("green").or eq("yellow").or eq("red") end it "passes when using boolean OR | alias" do expect(light.color).to eq("green") | eq("yellow") | eq("red") end end
"assigns :user" do user = double(:user) allow(User).to receive(:find).with("1").and_return(user) get :show, id: 1 expect(assigns[:user]).to eq(user) end end end
subscription" do it "charges user with their plan" do user = double(:user, active_subscription?: true) creditcard_charger = double(:creditcard_charger) expect(creditcard_charger).to receive(:charge).with(user) monthly_charger = MonthlySubscriptionCharger.new(user, creditcard_charger) monthly_charger.call end end end
do it "charges user with their plan" do user = double(:user, active_subscription?: true) creditcard_charger = double(:creditcard_charger, charge: true) monthly_charger = MonthlySubscriptionCharger.new(user, creditcard_charger) monthly_charger.call expect(creditcard_charger).to have_received(:charge).with(user) end end end
do it "charges user with their plan" do user = double(:user, active_subscription?: true) creditcard_charger = double(:creditcard_charger).as_null_object monthly_charger = MonthlySubscriptionCharger.new(user, creditcard_charger) monthly_charger.call expect(creditcard_charger).to have_received(:charge).with(user) end end end
do it "charges user with their plan" do user = double(:user, active_subscription?: true) creditcard_charger = spy(:creditcard_charger) monthly_charger = MonthlySubscriptionCharger.new(user, creditcard_charger) monthly_charger.call expect(creditcard_charger).to have_received(:charge).with(user) end end end
:feature do scenario "User creates a new widget" do visit "/widgets/new" fill_in "Name", :with => "My Widget" click_button "Create Widget" expect(page).to have_text("Widget was successfully created.") end end
do it "return full name of user" do user = User.new(first_name: 'Samnang', last_name: 'Chhun') result = user.full_name expect(result).to eq('Samnang Chhun') end end end
User.new(attributes) } context "when passing valid attributes" do let(:attributes) { { first_name: "Samnang", last_name: "Chhun" } } it "returns true" do expect(user.valid?).to eq(true) end end context "when passing invalid attributes" do let(:attributes) { { first_name: nil, last_name: "Chhun" } } it "returns false" do expect(user.valid?).to eq(false) end end end end
passing valid attributes" do it "returns true" do user = build_user(first_name: "Samnang", last_name: "Chhun") expect(user.valid?).to eq(true) end end context "when passing invalid attributes" do it "returns false" do user = build_user(first_name: nil, last_name: "Chhun") expect(user.valid?).to eq(false) end end def build_user(attributes) User.new(attributes) end end end
FeatureToggle.has_access?(user, beta_feature) end end RSpec.describe User do subject { build_stubbed(:beta_user) } it { is_expected.to have_access_to :mystery_machine } end
passing name" do it "returns hello message with passing name" do result = HelloMessage.new("Samnang").result expect(result).to eq("Hello Samnang!") end end context "without passing name" do it "returns the default of hello message" do result = HelloMessage.new.result expect(result).to eq("Hello World!") end end end
"return full name of user" do user = FactoryGirl.create(:user, first_name: "Samnang", last_name: "Chhun") expect(user.full_name).to eq("Samnang Chhun") end end end