rspec

Can I get RSpec to only run changed specs?

会有一股神秘感。 提交于 2020-07-18 18:00:30
问题 I have a test suite for a very large project (~ 3800 individual examples) that I'm updating from RSpec 2.14 to 3.6. I have just run a replace-all for s/be_true/be true/ , but some of them should be_truthy instead, and these specs are failing. I can extract the changed lines from git diff - with a little work - but then I need to feed these into RSpec's config.filter_run , and it doesn't seem to like me doing that for the locations filter (the one activated when you specify a rspec path/to

before(:each) vs just before

一个人想着一个人 提交于 2020-07-18 08:51:32
问题 I am new to ruby on rails. And playing around with testing Is there a difference between before(:each) do #some test code end and before do #some test code end 回答1: The before method accepts a scope parameter that defaults to :each . When you leave it out, it's implied that you mean :each , so your two examples do the exact same thing. Here is a helpful tidbit from the RSpec RDoc, Module: RSpec::Core::Hooks#before: Parameters: scope (Symbol) — :each , :all , or :suite (defaults to :each )

RSpec mock method inside of select loop

本小妞迷上赌 提交于 2020-07-10 07:28:29
问题 I want to test simple class which iterate through array of hashes and return only those with status Pending which were updated more than 2 days ago. class FetchPending PROJECT_KEY = 'TPFJT' TWO_DAYS = Time.now - 2 * 24 * 60 * 60 def call project.select do |issue| issue.fields.dig('status', 'name') == 'Pending' && DateTime.parse(issue.fields.dig('updated')) < TWO_DAYS end end private def project @project ||= Jira::ProjectConnection.new(PROJECT_KEY).call end end How to test fields method which

how to check array changes in rspec after a service call?

风格不统一 提交于 2020-07-09 05:22:18
问题 The goal is simple example we have an array [ {name: "ghost", state: "rejected"}, {name: "donkey", state: "rejected"} ] After running the Service call UpdateAllUsers , it would change all the users to 'accepted' [ {name: "ghost", state: "accepted"}, {name: "donkey", state: "accepted"} ] The question here is how do i check all the object in the array to have the same value after that service call in rspec? example in rspec describe 'call' do let(:all_users) { build(:users, 2, state: "rejected"

How do I test the rescue block of a method with rspec mocks 3.3

心已入冬 提交于 2020-06-28 08:21:28
问题 Help me make this test pass: Here is an example of some rspec code, class User attr_accessor :count def initialize @count = 0 end # sometimes raises def danger puts "IO can be dangerous..." rescue IOError => e @count += 1 end #always raises def danger! raise IOError.new rescue IOError => e @count += 1 end end describe User do describe "#danger!" do it "its rescue block always increases the counter by one" do allow(subject).to receive(:'danger!') expect { subject.danger! }.to change(subject,

Emulating a clipboard copy/paste with Selinum + Capybara

拈花ヽ惹草 提交于 2020-06-27 09:44:20
问题 I have a "Copy Link" button in my frontend UI. When clicked, the URL inside an input box is copied to the user's clipboard with this JS: const copyTextarea = document.querySelector("#copy-link-button"); copyTextarea.focus(); copyTextarea.select(); document.execCommand('copy'); When I try it out locally, this functionality works perfectly so I know the feature itself is working correctly. However I'm unable to test the copy with Capybara. I know from this post that Capybara does not provide a

localjumperror no block given (yield)

落花浮王杯 提交于 2020-06-26 06:03:54
问题 When i ran my spec it shows localjumperror no block given (yield) My service file service/update_many_post.rb class UpdateManyPost def call posts.each do |post| response = UpdateAPost.new(post: post).call yield response end end private def posts Post.all end end /service/update_a_post.rb class UpdateAPost def initialize(post:) @post = post end def call @post.title = "I am great" @post.save end end This is how I call the service. UpdateManyPost.new.call do |response| puts(response) end My

How to run multiple spec files in RSpec using single command in terminal?

生来就可爱ヽ(ⅴ<●) 提交于 2020-06-17 01:38:29
问题 I need to run RSpec at one go for multiple files of my choice can anyone guide me through it? I am a beginner so please explain clearly 回答1: Yes, you can. For multiple files without a pattern You can use the following syntax to run your specs for multiple files: rspec path/to/first/file path/to/second/file Multiple files with pattern If you wish to run spec from some specific folders then you might use rspec --pattern=./spec/features/**/*_spec.rb If you want to exclude some files rspec -