Dataset Viewer
Auto-converted to Parquet Duplicate
INSTRUCTION
stringlengths
202
35.5k
RESPONSE
stringlengths
75
161k
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true class TagFollowingService def initialize(user=nil) @user = user end def create(name) name_normalized = ActsAsTaggableOn::Tag.normalize(name) raise ArgumentError, "Name field null or empty" if name_normalized.blank? ...
# frozen_string_literal: true describe TagFollowingService do before do add_tag("tag1", alice) add_tag("tag2", alice) end describe "#create" do it "Creates new tag with valid name" do name = SecureRandom.uuid expect(alice.followed_tags.find_by(name: name)).to be_nil tag_data = tag_...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true class AspectsMembershipService def initialize(user=nil) @user = user end def create(aspect_id, person_id) person = Person.find(person_id) aspect = @user.aspects.where(id: aspect_id).first raise ActiveRecord::Rec...
# frozen_string_literal: true describe AspectsMembershipService do before do @alice_aspect1 = alice.aspects.first @alice_aspect2 = alice.aspects.create(name: "another aspect") @bob_aspect1 = bob.aspects.first end describe "#create" do context "with valid IDs" do it "succeeds" do ...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true class LikeService def initialize(user=nil) @user = user end def create_for_post(post_id) post = post_service.find!(post_id) user.like!(post) end def create_for_comment(comment_id) comment = comment_service....
# frozen_string_literal: true describe LikeService do let(:post) { alice.post(:status_message, text: "hello", to: alice.aspects.first) } let(:alice_comment) { CommentService.new(alice).create(post.id, "This is a wonderful post") } let(:bobs_comment) { CommentService.new(bob).create(post.id, "My post was better t...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true class StatusMessageCreationService include Rails.application.routes.url_helpers def initialize(user) @user = user end def create(params) validate_content(params) build_status_message(params).tap do |status_messa...
# frozen_string_literal: true describe StatusMessageCreationService do describe "#create" do let(:aspect) { alice.aspects.first } let(:text) { "I'm writing tests" } let(:params) { { status_message: {text: text}, aspect_ids: [aspect.id.to_s] } } it "returns the cre...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true class PostService def initialize(user=nil) @user = user end def find(id) if user user.find_visible_shareable_by_id(Post, id) else Post.find_by_id_and_public(id, true) end end def find!(id_or_gui...
# frozen_string_literal: true describe PostService do let(:post) { alice.post(:status_message, text: "ohai", to: alice.aspects.first) } let(:public) { alice.post(:status_message, text: "hey", public: true) } describe "#find" do context "with user" do it "returns the post, if it is the users post" do ...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true class NotificationService NOTIFICATION_TYPES = { Comment => [Notifications::MentionedInComment, Notifications::CommentOnPost, Notifications::AlsoCommented], Like => [Notifications::Liked, Notifications::LikedC...
# frozen_string_literal: true describe NotificationService do describe "notification interrelation" do context "with mention in comment" do let(:status_message) { FactoryBot.create(:status_message, public: true, author: alice.person).tap {|status_message| eve.comment!(status_message, "wha...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true # Encapsulates logic of processing diaspora:// links class DiasporaLinkService attr_reader :type, :author, :guid def initialize(link) @link = link.dup parse end def find_or_fetch_entity if type && guid enti...
# frozen_string_literal: true describe DiasporaLinkService do let(:service) { described_class.new(link) } describe "#find_or_fetch_entity" do context "when entity is known" do let(:post) { FactoryBot.create(:status_message) } let(:link) { "diaspora://#{post.author.diaspora_handle}/post/#{post.guid...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true class PollParticipationService def initialize(user) @user = user end def vote(post_id, answer_id) answer = PollAnswer.find(answer_id) @user.participate_in_poll!(target(post_id), answer) if target(post_id) end p...
# frozen_string_literal: true describe PollParticipationService do let(:poll_post) { FactoryBot.create(:status_message_with_poll, public: true) } let(:poll_answer) { poll_post.poll.poll_answers.first } describe "voting on poll" do it "succeeds" do expect(poll_service.vote(poll_post.id, poll_answer.id)...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true class ReshareService def initialize(user=nil) @user = user end def create(post_id) post = post_service.find!(post_id) post = post.absolute_root if post.is_a? Reshare user.reshare!(post) end def find_for_pos...
# frozen_string_literal: true describe ReshareService do let(:post) { alice.post(:status_message, text: "hello", public: true) } describe "#create" do it "doesn't create a reshare of my own post" do expect { ReshareService.new(alice).create(post.id) }.to raise_error RuntimeError end ...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true class PhotoService def initialize(user=nil, deny_raw_files=true) @user = user @deny_raw_files = deny_raw_files end def visible_photo(photo_guid) Photo.owned_or_visible_by_user(@user).where(guid: photo_guid).first ...
# frozen_string_literal: true describe PhotoService do before do alice_eve_spec = alice.aspects.create(name: "eve aspect") alice.share_with(eve.person, alice_eve_spec) alice_bob_spec = alice.aspects.create(name: "bob aspect") alice.share_with(bob.person, alice_bob_spec) @alice_eve_photo = alice.p...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true class ConversationService def initialize(user=nil) @user = user end def all_for_user(filter={}) conversation_filter = {} unless filter[:only_after].nil? conversation_filter = \ "conversations.created_a...
# frozen_string_literal: true describe ConversationService do before do opts = { subject: "conversation subject", message: {text: "conversation text"}, participant_ids: [bob.person.id] } @conversation = alice.build_conversation(opts) @conversation.created_at = 2.hour...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true class CommentService def initialize(user=nil) @user = user end def create(post_id, text) post = post_service.find!(post_id) user.comment!(post, text) end def find_for_post(post_id) post_service.find!(post_i...
# frozen_string_literal: true describe CommentService do let(:post) { alice.post(:status_message, text: "hello", to: alice.aspects.first) } describe "#create" do it "creates a comment on my own post" do comment = CommentService.new(alice).create(post.id, "hi") expect(comment.text).to eq("hi") ...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true require 'csv' # NOTE: This is a deprecated service, only kept to not break ongoing imports # on upgrade. See `BulkImportService` for its replacement. class ImportService < BaseService ROWS_PROCESSING_LIMIT = 20_000 def call(imp...
# frozen_string_literal: true require 'rails_helper' RSpec.describe ImportService, type: :service do include RoutingHelper let!(:account) { Fabricate(:account, locked: false) } let!(:bob) { Fabricate(:account, username: 'bob', locked: false) } let!(:eve) { Fabricate(:account, username: 'eve', domain:...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true class AuthorizeFollowService < BaseService include Payloadable def call(source_account, target_account, **options) if options[:skip_follow_request] follow_request = FollowRequest.new(account: source_account, target_acco...
# frozen_string_literal: true require 'rails_helper' RSpec.describe AuthorizeFollowService, type: :service do subject { described_class.new } let(:sender) { Fabricate(:account, username: 'alice') } describe 'local' do let(:bob) { Fabricate(:account, username: 'bob') } before do FollowRequest.cr...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true class PrecomputeFeedService < BaseService include Redisable def call(account) FeedManager.instance.populate_home(account) ensure redis.del("account:#{account.id}:regeneration") end end ```
# frozen_string_literal: true require 'rails_helper' RSpec.describe PrecomputeFeedService, type: :service do subject { described_class.new } describe 'call' do let(:account) { Fabricate(:account) } it 'fills a user timeline with statuses' do account = Fabricate(:account) status = Fabricate(:...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true class PostStatusService < BaseService include Redisable include LanguagesHelper MIN_SCHEDULE_OFFSET = 5.minutes.freeze class UnexpectedMentionsError < StandardError attr_reader :accounts def initialize(message, acco...
# frozen_string_literal: true require 'rails_helper' RSpec.describe PostStatusService, type: :service do subject { described_class.new } it 'creates a new status' do account = Fabricate(:account) text = 'test status update' status = subject.call(account, text: text) expect(status).to be_persist...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true class AccountSearchService < BaseService attr_reader :query, :limit, :offset, :options, :account MENTION_ONLY_RE = /\A#{Account::MENTION_RE}\z/i # Min. number of characters to look for non-exact matches MIN_QUERY_LENGTH = 5 ...
# frozen_string_literal: true require 'rails_helper' describe AccountSearchService, type: :service do describe '#call' do context 'with a query to ignore' do it 'returns empty array for missing query' do results = subject.call('', nil, limit: 10) expect(results).to eq [] end ...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true class SoftwareUpdateCheckService < BaseService def call clean_outdated_updates! return unless SoftwareUpdate.check_enabled? process_update_notices!(fetch_update_notices) end private def clean_outdated_updates! ...
# frozen_string_literal: true require 'rails_helper' RSpec.describe SoftwareUpdateCheckService, type: :service do subject { described_class.new } shared_examples 'when the feature is enabled' do let(:full_update_check_url) { "#{update_check_url}?version=#{Mastodon::Version.to_s.split('+')[0]}" } let(:de...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true class UnsuspendAccountService < BaseService include Payloadable # Restores a recently-unsuspended account # @param [Account] account Account to restore def call(account) @account = account refresh_remote_account! ...
# frozen_string_literal: true require 'rails_helper' RSpec.describe UnsuspendAccountService, type: :service do shared_context 'with common context' do subject { described_class.new.call(account) } let!(:local_follower) { Fabricate(:user, current_sign_in_at: 1.hour.ago).account } let!(:list) {...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true class AfterBlockDomainFromAccountService < BaseService include Payloadable # This service does not create an AccountDomainBlock record, # it's meant to be called after such a record has been created # synchronously, to "clean...
# frozen_string_literal: true require 'rails_helper' RSpec.describe AfterBlockDomainFromAccountService, type: :service do subject { described_class.new } let!(:wolf) { Fabricate(:account, username: 'wolf', domain: 'evil.org', inbox_url: 'https://evil.org/inbox', protocol: :activitypub) } let!(:alice) { Fabrica...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true class BlockDomainService < BaseService attr_reader :domain_block def call(domain_block, update = false) @domain_block = domain_block process_domain_block! process_retroactive_updates! if update end private def...
# frozen_string_literal: true require 'rails_helper' RSpec.describe BlockDomainService, type: :service do subject { described_class.new } let!(:bad_account) { Fabricate(:account, username: 'badguy666', domain: 'evil.org') } let!(:bad_status_plain) { Fabricate(:status, account: bad_account, text: 'You suck') } ...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true class BlockService < BaseService include Payloadable def call(account, target_account) return if account.id == target_account.id UnfollowService.new.call(account, target_account) if account.following?(target_account) ...
# frozen_string_literal: true require 'rails_helper' RSpec.describe BlockService, type: :service do subject { described_class.new } let(:sender) { Fabricate(:account, username: 'alice') } describe 'local' do let(:bob) { Fabricate(:account, username: 'bob') } before do subject.call(sender, bob) ...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true class UnfollowService < BaseService include Payloadable include Redisable include Lockable # Unfollow and notify the remote user # @param [Account] source_account Where to unfollow from # @param [Account] target_account W...
# frozen_string_literal: true require 'rails_helper' RSpec.describe UnfollowService, type: :service do subject { described_class.new } let(:sender) { Fabricate(:account, username: 'alice') } describe 'local' do let(:bob) { Fabricate(:account, username: 'bob') } before do sender.follow!(bob) ...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true class SuspendAccountService < BaseService include Payloadable # Carry out the suspension of a recently-suspended account # @param [Account] account Account to suspend def call(account) return unless account.suspended? ...
# frozen_string_literal: true require 'rails_helper' RSpec.describe SuspendAccountService, type: :service do shared_examples 'common behavior' do subject { described_class.new.call(account) } let!(:local_follower) { Fabricate(:user, current_sign_in_at: 1.hour.ago).account } let!(:list) { Fabr...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true class BulkImportService < BaseService def call(import) @import = import @account = @import.account case @import.type.to_sym when :following import_follows! when :blocking import_blocks! when :mu...
# frozen_string_literal: true require 'rails_helper' RSpec.describe BulkImportService do subject { described_class.new } let(:account) { Fabricate(:account) } let(:import) { Fabricate(:bulk_import, account: account, type: import_type, overwrite: overwrite, state: :in_progress, imported_items: 0, processed_item...
End of preview. Expand in Data Studio

YAML Metadata Warning:empty or missing yaml metadata in repo card

Check out the documentation for more information.

Ruby dataset

Custom ruby dataset

  • rspec_dataset

Bigcode dataset

  • ruby-dataset
  • shell-dataset
  • python-dataset
  • sql-dataset

rspec dataset

Specs are exclusively gathered from the 'app/services' directory within the specified repositories. This approach is employed since the majority of business logic is encapsulated within these services

REPO_URLS = [
    'https://github.com/diaspora/diaspora.git',
    'https://github.com/mastodon/mastodon.git',
    'https://github.com/gitlabhq/gitlabhq.git',
    'https://github.com/discourse/discourse.git',
    'https://github.com/chatwoot/chatwoot.git',
    'https://github.com/opf/openproject.git',
]

output

Repository           Avg Source Lines Avg Test Lines  Test Cases
diaspora             62              156             12
mastodon             97              131             59
gitlabhq             66              154             952
discourse            188             303             49
chatwoot             63              107             50
openproject          86              178             98
------------------------------------------------------------
Total                74              159             1220
------------------------------------------------------------

# avg_source_lines = [62, 97, 66, 188, 63, 86]
# avg_test_lines = [156, 131, 154, 303, 107, 178]
# test_cases = [12, 59, 952, 49, 50, 98]

# Assuming an average of 10 tokens per line of code, which is a rough average for programming languages
# tokens_per_line = 10

# Calculating the total tokens for source and test lines
# total_source_tokens = sum([lines * tokens_per_line for lines in avg_source_lines])
# total_test_tokens = sum([lines * tokens_per_line for lines in avg_test_lines])

# Total tokens
# total_tokens = total_source_tokens + total_test_tokens

# Average tokens per test case
# avg_tokens_per_test_case = total_tokens / sum(test_cases)

# total_tokens, avg_tokens_per_test_case
# -> (15910, 13.040983606557377)

When you prepare data for training or inference with an LLM, each example (in this case, each test case or code snippet) needs to fit within this context window. The average tokens per test case calculated earlier (approximately 13.04 tokens) is well within the limits of LLMs

Downloads last month
27